Use a Command Line script to configure a Static IP address or a Dynamic IP address

by on Jul.24, 2009, under Microsoft, Tools

Recently a customer had an issue with travelling back and forth between two networks with his laptop. One network (his home) used dynamic IP, the other (his office) used static IP. The constant messing about with the control panel and network connections was causing him grief, and sometimes he would forget the numbers to key in. So, I wrote two scripts and placed them on his desktop.

The first script, ip-dynamic.bat, configures the IP address and DNS as dynamic, and clears the caches:

netsh interface ip delete dns "Wireless Network Connection" all
netsh interface ip set address "Wireless Network Connection" dhcp
netsh interface ip delete dns "Wireless Network Connection" all

netsh interface ip delete dns "Local Area Connection" all
netsh interface ip set address "Local Area Connection" dhcp
netsh interface ip delete dns "Local Area Connection" all

ipconfig /release
ipconfig /flushdns
netsh interface ip delete arpcache
ipconfig /renew

The second script, ip-static.bat, configures the IP and DNS addresses as static, and also clears the caches:

netsh interface ip delete dns "Wireless Network Connection" all
netsh interface ip add dns "Wireless Network Connection" 192.168.0.1
netsh interface ip add dns "Wireless Network Connection" 4.2.2.3 index=2
netsh interface ip set address "Wireless Network Connection" static 192.168.0.190 255.255.255.0 192.168.0.1 1

netsh interface ip delete dns "Local Area Connection" all
netsh interface ip add dns "Local Area Connection" 192.168.0.1
netsh interface ip add dns "Local Area Connection" 4.2.2.3 index=2
netsh interface ip set address "Local Area Connection" static 192.168.0.191 255.255.255.0 192.168.0.1 1

ipconfig /release
ipconfig /flushdns
netsh interface ip delete arpcache
ipconfig /renew

To adapt these scripts to your situation, you will undoubtedly need to change the IP addresses and maybe even the interface names.


Comments are closed.

RSS feed for this post (comments) Share

Sugarloaf Tech, Inc.