21
May
这个shell可以辅助你:
1. 来回切换预设好的两个(你也可以改为更多个)网络设置;
2. 自动获取网络设置;
3. 手动设置网络环境(一般临时用一下);
4. 启用/禁用网卡;
5. 查看网络设置。
代码保存为*.bat/*.cmd均可,双击执行。
注:因为Win2003的命令行代码页默认不支持中文(可以通过改注册表修正)这里把网卡名称改成了Lineate,如果你的命令行支持中文(也可以通过修改该批处理文件的快捷方式属性->选项->当前代码页为936),把Lineate改成你的网卡名称(如“本地连接”)即可。
参考:http://windowsitpro.com/articles/index.cfm?articleid=41111&cpage=1#feedbackAnchor
@echo off title Switch Network Settingset card=Lineate set house_ip=192.168.2.98 set house_mask=255.255.255.0 set house_gway=192.168.2.1 set house_dns0=127.0.0.1 set house_dns1=202.96.134.133 set office_ip=192.168.1.113 set office_mask=255.255.255.0 set office_gway=192.168.1.1 set office_dns0=192.168.1.1 set office_dns1=202.101.172.35 :Lab_choice cls echo Choice the Network type (for [%card%]): echo ------------------------------------------------------------------------- echo * [1] : [ House ] Network Setting:%house_ip% %house_mask% %house_gway% echo * [2] : [ Office ] Network Setting:%office_ip% %office_mask% %office_gway% echo * [3] : Set Address by Youself. echo * [4] : Auto. echo * echo * [5] : Disable Interface. echo * [6] : Enable Interface. echo * [7] : Change Network Card Name (Current : %card%) echo * [9] : Show Status. echo * echo * [?] : Help. echo * [0] : Exit. echo ------------------------------------------------------------------------- set /p type=Choice: if %type%==0 exit if %type%==exit exit if %type%==quit exit if %type%==1 goto Lab_house if %type%==2 goto Lab_office if %type%==3 goto Lab_userset if %type%==4 goto Lab_set_dhcp if %type%==5 goto Lab_disable if %type%==6 goto Lab_enable if %type%==7 goto Lab_changeCard if %type%==9 goto done if %type%==? goto Lab_help goto Lab_choice :Lab_changeCard cls echo All Network Card Config Infomation: echo ------------------------------------------------------------------------- netsh interface ip show config echo ------------------------------------------------------------------------- set /p card=Input Network Card Name: goto Lab_choice rem ========================================================================== :Lab_userset cls echo Input Network echo ------------------------------------------------------------------------- set /p ip=IP Address: set /p mask=Subnet Mask: set /p gway=Default Gateway: set /p dns0=Default DNS Servers: set /p dns1=Spare DNS Servers: echo ------------------------------------------------------------------------- echo [y/Y] : Update network setting immediately. echo [n/N] : Cancel and goto main menu. set /p confirm=Config the Network Setting(y/n): if %confirm%==y goto Lab_set_static goto Lab_choice :Lab_house set ip=%house_ip% set mask=%house_mask% set gway=%house_gway% set dns0=%house_dns0% set dns1=%house_dns1% goto Lab_set_static :Label_office set ip=%office_ip% set mask=%office_mask% set gway=%office_gway% set dns0=%office_dns0% set dns1=%office_dns1% goto Lab_set_static rem ========================================================================== :Lab_set_static echo Reset Network Setting... netsh interface ip reset "%card%" echo Setting IP Address and Subnet Mask... netsh interface ip set address "%card%" source=static addr=%ip% mask=%mask% echo Setting Default Gateway... netsh interface ip set address "%card%" gateway=%gway% gwmetric=1 echo Setting Default DNS Servers... netsh interface ip set dns "%card%" static %dns0% primary echo Adding Spare DNS Servers... netsh interface ip add dns "%card%" addr=%dns1% index=2 goto done rem ========================================================================== :Lab_set_dhcp echo Auto get IP Address... netsh interface ip set address "%card%" source=dhcp echo Auto get DNS Servers... netsh interface ip set dns "%card%" source=dhcp goto done :Lab_disable netsh int set interface name="%card%" admin=disabled goto done :Lab_enable netsh int set interface name="%card%" admin=enabled goto done rem ========================================================================== :done echo Current Network Setting: echo ------------------------------------------------------------------------- netsh interface ip show config "%card%" echo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ipconfig /all pause goto Lab_choice :Lab_help cls echo Help Infomation - Advance Usage echo ------------------------------------------------------------------------- echo ? get help. echo. pause goto Lab_choice