单网卡快速更换IP地址配置的方法

由于在公司和在家里上网的IP配置不同,每次回家或者上班时都需要重新设置一下IP地址,极不方便。今天无意中看到一个可以快速解决的方法:写一个.bat批处理文件,内容如下

@echo off
rem eth
set eth=”本地连接”
rem ip
set ip=192.168.1.199
rem gw
set gw=192.168.1.1
rem netmasks
set netmasks=255.255.255.0
rem dns
set dns=192.168.1.1
rem dns2
set dns2=192.168.0.1

echo 正在将本机IP更改到: %ip%
rem
if %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% > nul
if not %gw%==none netsh interface ip set address %eth% static %ip% %netmasks% %gw% 1 > nul
netsh interface ip set dns %eth% static %dns% PRIMARY > nul
netsh interface ip add dns %eth% %dns2% > nul
echo…………………….
echo 检查当前本机IP:
ipconfig
echo…………………….
echo 成功将本机IP更改为%ip%
pause
close

文件保存为home.bat,其中配置根据自己实际情况写;同样的方法再写另外一个文件:office.bat。切换网络环境时只需点击执行文件即可。

感谢网友sorghum对命令的解释,另:命令执行起来稍稍有些慢。

No Response for '单网卡快速更换IP地址配置的方法'

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>