IP Address change

Started by mcvpjd3, October 11, 2016, 07:02:26 AM

Previous topic - Next topic

mcvpjd3

Hi Folks, one of my users has asked me to write a script which I though might be an easy script. The more I think about it the less easy it seems to be so just wondered if anyone here has done anything similar.

What I need is a script to change from a DHCP IP to a Static IP for a laptop. The difficulty is this may be required on more that one laptop with different hardware or LAN names. I started looking into using WMI to get network adaptors but it seems messy and overly complicated.

Has anyone done anything like this or some way of listing the entries available in "Network Connections" on a Win7 PC?

Thanks

td

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pamsniffer

look at netsh

netsh interface ip add dns "connection name" 208.67.222.222

snowsnowsnow

netsh is definitely the way to go, but I think the problem here (in this thread) is that the OP wants it to be more "user-proof" than netsh is by default.  That is, he wants it to figure out the various bits of detail (ip addr, DNS, netmask, etc) that are needed by netsh "automatically".

To put this another way, I've written scripts (actually, ordinary DOS/Windows batch files, not WBT scripts) to do this - that is, to switch back and forth between DHCP and static IP - and I've found both of the following to be true:
1) It is not trivial.  By the time you're done, you've got quite a lengthy script on your hands.
2) It requires a fair amount of user input - i.e., the presumed user has to pretty much know what is going on and what needs changing.  Luckily, the presumed user of most of my scripts is, you guessed it, me.

P.S.  Just out of curiosity, why are you doing this?  I.e., anytime people start asking about static IP, the obvious question that eventually comes out is: Why?