批处理更改网络设置

在公司用固定IP,在家用自动获取,公司是铁通,家里是联通,上班下班都要改配置,麻烦死了。

想了个办法,用批处理来更改配置

我用的虚拟机桥接,所以改IP要改如图所示中的这个

点击查看原图

看清上面的名字"vEthernet (外部)"哟,很重要,下面要用到

将下面命令保存为ChangeIP.bat

@echo off
netsh interface ip show config "vEthernet (外部)"|find /i "否"&&set a=0||set a=1
if %a%==0 (
  netsh interface ip set address name="vEthernet (外部)" source=dhcp
  netsh interface ip set dns "vEthernet (外部)" source=dhcp
  ipconfig /flushdns
)
if %a%==1 (
  netsh interface ip set address name="vEthernet (外部)" source=static addr=192.168.0.5 mask=255.255.255.0 gateway=192.168.0.1 gwmetric=0
  netsh interface ip set dns "vEthernet (外部)" source=static addr=219.150.32.132 register=PRIMARY
  netsh interface ip add dns "vEthernet (外部)" addr=8.8.8.8 index=2
  ipconfig /flushdns
)
pause>nul


我的系统是Windows 8,得右键用管理员身份运行才可以 

上一篇‡: 在winform中设置快捷键

下一篇‡: 小火柴.NET正式更名为I'm 大宝

最近回复