使用命令行切换IP地址
@ netsh interface ip set address "Local Area Connection" static 192.168.20.177 255.255.255.128 192.168.20.129
@ netsh interface ip set dns "Local Area Connection" dhcp
第一行设置本地连接使用静态IP地址,192.168.20.177 并同时指定了掩码和网关;
第二行设置本地连接使用动态的 DNS;
需要注意的是“Local Area Connection” 是网络连接的名字,不能随便写的,否则报错,并且设置不成功
在中文的Windows操作系统上这个名字一般是“本地网络连接”,上面的名字是英文版 Windows 7 上网络连接的名字,如果不知道可以在控制面板中找到;
如果经常在多个场合使用,可以写多个批处理文件,然后再不同的场合使用不同的批处理,会方便很多;
但是仅仅切换IP地址还不够,经常需要同时设置IE的代理服务器,可以使用如下的脚本:
@ reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
@ reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /t REG_SZ /d "192.168.0.1:8080" /f
@ reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOveride /t REG_SZ /d "192.*;<local>" /f
如果要取消 IE 的代理设置,那么只需要将上述脚本中第一行中的值替换为 0 就可以了,如下所示:
@ reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f