Switching IP Addresses using Batch files
Written on June 10, 2010.

Having been provided with a client laptop from office, I need to work from home also as and when required. This created a frustrating problem for me.
When at office I had to use the assigned specific IP complete with subnet mask, default gateway and dns servers.
At home my router was configured for DHCP mode.
This let me to constantly change between static ip and DHCP when at office and when I returned to home from office.
To spare me the troubles i wrote 2 small batch files.
One was for when I was at office, which automatically changed the network adapter’s settings specific to the office and the other was for home to quickly revert back to DHCP.
I am posting both the scripts here so that if you are in the same boat as me, then you would not have to suffer like me …
Script for connection with static ip, subment mask, default gateway and dns servers provided
@ECHO OFF set varip=xxx.xxx.xxx.xxx set varsm=xxx.xxx.xxx.xxx set vargw=xxx.xxx.xxx.xxx set vardns1=xxx.xxx.xxx.xxx set vardns2=xxx.xxx.xxx.xxx ECHO Setting IP Address and Subnet Mask netsh int ip set address name = "Local Area Connection" source = static addr = %varip% mask = %varsm% ECHO Setting Gateway netsh int ip set address name = "Local Area Connection" gateway = %vargw% gwmetric = 1 ECHO Setting Primary DNS netsh int ip set dns name = "Local Area Connection" source = static addr = %vardns1% ECHO Setting Secondary DNS netsh int ip add dns name = "Local Area Connection" addr = %vardns2% pause

Script output after being executed
Script for DHCP connection
@ECHO OFF ECHO Resetting IP Address and Subnet Mask For DHCP netsh int ip set address name = "Local Area Connection" source = dhcp ECHO Resetting DNS For DHCP netsh int ip set dns name = "Local Area Connection" source = dhcp pause

Script output after being executed
Instructions to use the scripts :
- Save the scripts with an extension “.bat”.
- Change the xxx.xxx.xxx.xxx vales for
- varip with the static ip provided
- varsm with the subnet mask
- vargw with the default gateway
- vardns1 with the dns server address
- vardns2 with the alternate dns server address.
- Execute the relevant file at the relevant place to have a hassle free change of network adapter address .
Use the script and have a nice time
Read more from the Miscellaneous, OS, Programming, Techie, Windows category.
If you would like to leave a comment, click here: Be the First to comment on Switching IP Addresses using Batch files.
If you enjoyed reading, consider sharing it on one of these social bookmarking sites :
If you liked this post, consider subscribing to the feed via RSS or Email to receive notifications as and when new posts are published.
My Chotu Died Young
Leave a Reply
© Copyright 4 Geeks From Net (2006-2010).Theme modified by 7sins.
All rights reserved.
For best results, please view with Firefox

