May be all of you already know how to do this... but I found how to rapidly change the IP address of my laptop just a few day ago![]()
I need to switch the IP because at work I need a static IP but at home I use a dynamic IP (via DHCP) so I tried to write two small .bat files that avoid me a lot of boring clicks on the network preferences dialog windows!
setip_stat.bat
setip_dhcp.batCode:@rem echo OFF set lan_name="Local Area Connection" rem define all the network addresses here set subnet=192.168.1 set lan_ip=%subnet%.22 set sub_net_mask=255.255.255.0 set gateway_addr=%subnet%.153 set pri_dns_addr=%subnet%.157 set sec_dns_addr=%subnet%.153 rem set the ip address @netsh interface ip set address name=%lan_name% source=static addr=%lan_ip% mask=%sub_net_mask% gateway=%gateway_addr% gwmetric=1 rem set the DNS @netsh interface ip set dns name=%lan_name% source=static addr=%pri_dns_addr% primary rem add an alternative DNS (optional) @netsh interface ip add dns name=%lan_name% addr=%gateway_addr% index=2
Alternatively, if you are familiar with the batch file sintax, it is possible to write a single .bat file passing one ore more parameters for switching among the different parts of the code.Code:@rem echo OFF set lan_name="Local Area Connection" rem set the ip address @netsh interface ip set address name=%lan_name% source=dhcp rem set the DNS @netsh interface ip set dns name=%lan_name% source=dhcp
I attached the script I'm currently using with my network.





Reply With Quote
Bookmarks