读书人

如何用代码修改IP地址,并且要同时修改

发布时间: 2012-02-01 16:58:19 作者: rapoo

怎么用代码修改IP地址,并且要同时修改两个IP,我只知道怎么修改一个IP
修改一个IP的代码如下,现求同时修改两个的!



@echo off
rem eth //eth 为网卡名称,可在网络连接中查询,如 "本地链接 "
set eth= "本地连接"
rem ip //ip 为你想更改的IP
set ip=192.168.10.242
rem ip2
set ip2=192.168.10.10
rem gateway //gateway 为网关地址
set gateway=192.168.10.250
rem netmasks //netmasks 为子网掩码
set netmasks=255.255.255.0
rem dns //dns 为首选DNS
set dns=202.96.134.133
rem dns2 //dns2 为备用DNS
set dns2=202.96.128.68
echo 正在将本机IP更改到: %ip% 请等候...
rem
if %gateway%==none netsh interface ip set address %eth% static %ip% %netmasks% %gateway% > nul
if not %gateway%==none netsh interface ip set address %eth% static %ip% %netmasks% %gateway% 1 > nul
if %dns%==none netsh interface ip set dns %eth% static %dns%> nul
if not %dns%==none netsh interface ip set dns %eth% static %dns%> nul
if %dns2%==none netsh interface ip add dns %eth% %dns2%> nul
if not %dns2%==none netsh interface ip add dns %eth% %dns2% 2> nul
if %gateway%==none netsh interface ip set address %eth% static %ip2% %netmasks% > nul
if not %gateway%==none netsh interface ip set address %eth% static %ip2% %netmasks% 2 > nul
echo.........................
echo 检查当前本机IP:
ipconfig
echo.........................
echo 成功将本机IP更改为%ip%!
pause
exit

因为一个是内网IP,一个是连接外网的IP,所以我需要能同时修改两个的

[解决办法]
给楼主写了个,参考看看

BatchFile code
@echo off  rem eth //eth 为网卡名称,可在网络连接中查询,如 "本地链接 "  set eth= "本地连接"  rem ip //ip 为你想更改的IP  set ip=192.168.10.242  rem ip2set ip2=192.168.10.10rem gateway //gateway 为网关地址  set gateway=192.168.10.250  rem netmasks //netmasks 为子网掩码  set netmasks=255.255.255.0  rem dns //dns 为首选DNS  set dns=202.96.134.133  rem dns2 //dns2 为备用DNS  set dns2=202.96.128.68  echo 正在将本机IP更改到: %ip% 请等候...  netsh inte ip set addr %eth% stat %ip% %netmasks% %gateway% noneecho 正在添加 %ip2% 到本机IP列表,请等候... netsh inte ip add addr %eth% %ip2% %netmasks%echo 正在设置首选DNS服务器IP地址为: %dns% 请稍后...netsh inte ip set dns %eth% stat %dns% register=primaryecho 正在设置备用DNS服务器IP地址为: %dns2% 请稍后...netsh inte ip add dns %eth% %dns2% index=2echo.........................  echo 检查当前本机IP:  ipconfig  echo.........................  echo 成功将本机IP更改为%ip%!  pause 

读书人网 >windows

热点推荐