从家里和公司使用的网络不同,经常需要来回切换,这里找了两个自动切换的bat,每次点一下就可以自动切换IP,具体如下:
脚本1:
- @echo off
- title Alpha - IP地址修改工具
- MODE con: COLS=80 lines=20
- rem IP地址列表
- set lname=本地连接
- rem 本地连接IP地址一 公司IP地址
- set lAdd1=192.168.1.75
- set lmask1=255.255.252.0
- set lGat1=192.168.1.1
- set ldns11=10.70.5.16
- ::set ldns12=202.106.196.115
- rem 本地连接IP地址二 家庭IP地址
- set lAdd2=192.168.0.115
- set lmask2=255.255.255.0
- set lGat2=192.168.0.1
- set ldns21=202.96.199.133
- set ldns22=202.106.196.115
- set wname=无线网络连接
- rem 无线连接IP地址一 公司IP地址
- set wAdd1=%lAdd1%
- set wmask1=%lmask1%
- set wGat1=%lGat1%
- set wdns11=%ldns11%
- set wdns12=%ldns12%
- rem 无线连接IP地址二 家庭IP地址
- set wAdd2=%lAdd2%
- set wmask2=%lmask2%
- set wGat2=%lGat2%
- set wdns21=%ldns21%
- set wdns22=%ldns21%
- :home
- cls
- @echo.
- @echo Alpha - IP地址修改工具 ( by -- 361way.com )
- @echo.
- @echo 1:设置 %lname%
- @echo 2:设置 %wname%
- @echo.
- @echo 警告:WIN7系统必须 单击右键 [以管理员身份运行(A)] !
- @echo.
- @echo.
- set shut=""
- set /p shut="请输入 【<1> 或 <2> 或 退出】 并按回车键 :"
- IF NOT "%shut%"=="" (
- if %shut% NEQ "" SET shut=%shut:~0,1%
- ) else (
- set shut="")
- if /i %shut%==1 goto locally
- if /i %shut%==2 goto wireless
- if /i %shut%==q exit
- goto home
- :locally
- cls
- @echo.
- @echo 修改 %lname% IP地址 ( by -- 361way.com )
- @echo.
- @echo 1:设置 %lname% 自动获取IP地址
- @echo 2:设置 %lname% IP地址为公司IP %lAdd1%
- @echo 3:设置 %lname% IP地址为专用IP %lAdd2%
- @echo.
- @echo.
- set shut=""
- set /p shut="请输入 【<1> 或 <2> 或 <3> 或 退出】 并按回车键 或者 按<回车键>返回主菜单 :"
- IF NOT "%shut%"=="" (
- if %shut% NEQ "" SET shut=%shut:~0,1%
- ) else (
- set shut="")
- if /i %shut%==1 goto locallyone
- if /i %shut%==2 goto locallytwo
- if /i %shut%==3 goto locallythree
- if /i %shut%==q exit
- goto home
- :wireless
- cls
- @echo.
- @echo 修改 %wname% IP地址 ( by -- 361way.com )
- @echo.
- @echo 1:设置 %wname% 自动获取IP地址
- @echo 2:设置 %wname% IP地址为公司IP %wAdd1%
- @echo 3:设置 %wname% IP地址为专用IP %wAdd2%
- @echo.
- @echo.
- set shut=""
- set /p shut="请输入 【<1> 或 <2> 或 <3> 或 退出】 并按回车键 或者 按<回车键>返回主菜单 :"
- IF NOT "%shut%"=="" (
- if %shut% NEQ "" SET shut=%shut:~0,1%
- ) else (
- set shut="")
- if /i %shut%==1 goto wirelessone
- if /i %shut%==2 goto wirelesstwo
- if /i %shut%==3 goto wirelessthree
- if /i %shut%==q exit
- goto home
- rem 设置 本地网络连接 开始
- :locallyone
- @echo.
- @echo 正在设置 %lname% IP地址 请稍后。。。
- call :autolocall %lname% >nul
- @echo 设置 %lname% 自动获取IP地址成功!!
- @echo.
- @echo.
- goto three
- :locallytwo
- @echo.
- @echo 正在设置 %lname% IP地址 请稍后。。。
- call :autowireless %wname% >nul
- cmd /c netsh interface ip set address name="%lname%" static %ladd1% %lmask1% %lGat1% >nul
- cmd /c netsh interface ip add dns name="%lname%" %ldns11% index=1 >nul
- cmd /c netsh interface ip add dns name="%lname%" %ldns12% index=2 >nul
- @echo 设置 %lname% IP地址成功!!!
- @echo.
- @echo 当前IP地址: %ladd1%
- @echo 当前子网掩码: %lmask1%
- @echo 当前默认网关: %lGat1%
- @echo 当前DNS1地址:%ldns11%
- @echo 当前DNS2地址:%ldns12%
- @echo.
- @echo.
- goto three
- :locallythree
- @echo.
- @echo 正在设置 %lname% IP地址 请稍后。。。
- call :autowireless %wname% >nul
- cmd /c netsh interface ip set address name="%lname%" static %ladd2% %lmask2% %lGat2% >nul
- cmd /c netsh interface ip add dns name="%lname%" addr=%ldns21% index=1 >nul
- cmd /c netsh interface ip add dns name="%lname%" addr=%ldns22% index=2 >nul
- @echo 设置 %lname% IP地址成功!!!
- @echo.
- @echo 当前IP地址: %ladd2%
- @echo 当前子网掩码: %lmask2%
- @echo 当前默认网关: %lGat2%
- @echo 当前DNS1地址:%ldns21%
- @echo 当前DNS2地址:%ldns22%
- @echo.
- @echo.
- goto three
- :: 设置 本地网络连接 结束
- :: 设置 无线网络连接 开始
- :wirelessone
- @echo.
- @echo 正在设置 %wname% IP地址 请稍后。。。
- call :autowireless %wname% >nul
- @echo 设置 %wname% 自动获取IP地址成功!!
- @echo.
- @echo.
- goto three
- :wirelesstwo
- @echo.
- @echo 正在设置 %wname% IP地址 请稍后。。。
- call :autolocall %lname% >nul
- cmd /c netsh interface ip set address name="%wname%" static %wadd1% %wmask1% %wGat1% >nul
- cmd /c netsh interface ip add dns name="%wname%" %wdns11% index=1 >nul
- cmd /c netsh interface ip add dns name="%wname%" %wdns12% index=2 >nul
- @echo 设置 %wname% IP地址成功!!!
- @echo.
- @echo 当前IP地址: %wadd1%
- @echo 当前子网掩码: %wmask1%
- @echo 当前默认网关: %wGat1%
- @echo 当前DNS1地址:%wdns11%
- @echo 当前DNS2地址:%wdns12%
- @echo.
- @echo.
- goto three
- :wirelessthree
- @echo.
- @echo 正在设置 %wname% IP地址 请稍后。。。
- call :autolocall %lname% >nul
- cmd /c netsh interface ip set address name="%wname%" static %wadd2% %wmask2% %wGat2% >nul
- cmd /c netsh interface ip add dns name="%wname%" %wdns121% index=1 >nul
- cmd /c netsh interface ip add dns name="%wname%" %wdns122% index=2 >nul
- @echo 设置 %wname% IP地址成功!!!
- @echo.
- @echo 当前IP地址: %wadd2%
- @echo 当前子网掩码: %wmask2%
- @echo 当前默认网关: %wGat2%
- @echo 当前DNS1地址:%wdns21%
- @echo 当前DNS2地址:%wdns22%
- @echo.
- @echo.
- goto three
- :: 设置 无线网络连接 结束
- :three
- ::pause >nul
- set shut=""
- set /p shut="请输入 【返回主菜单】 或者 按<其他键>退出:"
- IF NOT "%shut%"=="" (
- if %shut% NEQ "" SET shut=%shut:~0,1%
- ) else (
- set shut="")
- if /i %shut%==a goto home
- exit
- :autolocall
- cmd /c netsh interface ip set address name="%lname%" static 0.0.0.0 0.0.0.0 0.0.0.0 >nul
- cmd /c netsh interface ip set address name="%lname%" source=dhcp >nul
- cmd /c netsh interface ip set dns name="%lname%" source=dhcp >nul
- ::@echo 设置 %lname% 自动获取IP地址成功!
- goto :eof
- :autowireless
- cmd /c netsh interface ip set address name="%wname%" static 0.0.0.0 0.0.0.0 0.0.0.0 >nul
- cmd /c netsh interface ip set address name="%wname%" source=dhcp >nul
- cmd /c netsh interface ip set dns name="%wname%" source=dhcp >nul
- ::@echo 设置 %wname% 自动获取IP地址成功!
- goto :eof
脚本2:
- @echooff
- color 1f
- titlewindows 7 多网络环境自动切换管理
- echo.
- echo ********************************************
- echo *** windows 7 双网络自动切换管理 ***
- echo ********************************************
- echo *** 设置IP参数,设置IE代理 ***
- echo.
- echo.
- gotomenus
- :menus
- echo.
- echo 请选择:
- echo.
- echo 1切换到家庭代理网络
- echo.
- echo 2切换到学校自动获取IP地址网络。
- echo.
- echo 3放弃设备,退出
- echo.
- set /pselect=请输入菜单对应数字后回车:
- if /i"%select%" == "1" goto home
- if /i"%select%" == "2" goto school
- if /i"%select%" == "3" exit
- gotomenus
- :home
- cls
- netshinterface ip reset "无线网络连接"
- echo 设置IP...设置网关.....设置子网
- netshinterface ipv4 set address "无线网络连接" static 192.168.1.75 255.255.255.0 192.168.1.1
- echo 设置DNS...
- netshinterface ipv4 set dns name="无线网络连接" source=static addr=10.70.5.16
- ::netshinterface ipv4 add dns name="无线网络连接" addr=61.177.7.1 index=2
- echo 设置IE代理...
- echo 正在设置代理服务器……
- regadd "HKCU/Software/Microsoft/Windows/CurrentVersion/InternetSettings" /v ProxyEnable /t REG_DWORD /d 1 /f
- regadd "HKCU/Software/Microsoft/Windows/CurrentVersion/InternetSettings" /v ProxyServer /d "192.168.100.100:808" /f
- regadd "HKCU/Software/Microsoft/Windows/CurrentVersion/InternetSettings" /v ProxyOverride /t REG_SZ /d "" /f
- echo 正在刷新设置……
- ipconfig/flushdns
- gotoexit
- :school
- cls
- echo 设置学校网络自动IP地址.
- netshinterface ipv4 set address name="无线网络连接" source=dhcp
- echo 设置DNS...
- netshinterface ipv4 set dns name="无线网络连接" source=dhcp
- echo 正在清除代理服务器设置……
- echo 正在清空代理服务器设置……
- regadd "HKCU/Software/Microsoft/Windows/CurrentVersion/InternetSettings" /v ProxyEnable /t REG_DWORD /d 0 /f
- regadd "HKCU/Software/Microsoft/Windows/CurrentVersion/InternetSettings" /v ProxyServer /d "" /f
- regadd "HKCU/Software/Microsoft/Windows/CurrentVersion/InternetSettings" /v ProxyOverride /t REG_SZ /d 0 /f
- echo 代理服务器设置已经清空
- echo 正在刷新设置……
- ipconfig/flushdns
- gotoexit
- :exit
- cls
- echo.
- cho.
- echo.
- echo************恭喜!网络设置以完成。
- echo.
- echo.
- pause
- exit
两者本质上并无区别,都是通过netsh命令配合注册表修改的方式进行修改。