Skip to content

Instantly share code, notes, and snippets.

@ninehills
Created May 24, 2011 12:05
Show Gist options
  • Save ninehills/988593 to your computer and use it in GitHub Desktop.
Save ninehills/988593 to your computer and use it in GitHub Desktop.
Windows IP 快速切换脚本
@echo off&color 1E&title IP地址快速切换器
echo ┌────────────────────────────┐
echo | |
echo | 切换网络环境,请输入当前所在位置 │
echo | |
echo └────────────────────────────┘
:choice
set choice=
set /p choice=【实验室无线】请选择1,【实验室有线】请选择2,【宿舍无线】请选择3,【宿舍有线】请选择4:[1,2,3,4]?
if %choice%==4 goto dorm_lan
if %choice%==3 goto dorm_wlan
if %choice%==2 goto lab_lan
if %choice%==1 (goto lab_wlan) else (echo 输入错误,请重新输入&goto choice)
:lab_wlan
set eth="无线网络连接"
echo.
echo 正在切换到实验室无线环境
echo.
goto public
:lab_lan
set eth="本地连接"
set ip=202.113.229.252
set netmask=255.255.255.128
set gw=202.113.229.129
set dns1=8.8.8.8
set dns2=202.113.16.10
echo.
echo 切换到实验室有线环境
echo.
goto switch
:dorm_wlan
set eth="无线网络连接"
set ip=10.22.33.17
set netmask=255.255.255.0
set gw=10.22.33.1
set dns1=8.8.8.8
set dns2=202.113.16.10
echo.
echo 切换到宿舍无线环境
echo.
goto switch
:dorm_lan
set eth="本地连接"
set ip=10.22.33.18
set netmask=255.255.255.0
set gw=10.22.33.1
set dns1=8.8.8.8
set dns2=202.113.16.10
echo.
echo 切换到宿舍有线环境
echo.
goto switch
:switch
echo 正在设置IP地址 %ip%
netsh interface ip set address %eth% static %ip% %netmask% %gw% 1
echo 正在设置首选DNS服务器 %dns1%
netsh interface ip set dns %eth% static %dns1%
echo 正在设置备用DNS服务器 %dns2%
netsh interface ip add dns %eth% %dns2% index=2
echo.
echo 您的IP地址切换成功,当前IP地址为%ip%
echo.
goto end
:public
echo 正在设置IP地址为自动获得
netsh interface ip set address %eth% dhcp
echo 设置首选DNS服务器为自动获得
netsh interface ip set dns %eth% dhcp
echo 正在自动获取IP,请稍侯...
echo.
for /L %%x in (1 1 10) do set /p gu=■<nul&ping /n 2 127.1>nul
echo 100%%
echo.
echo 您的IP地址将切换成功,当前IP地址为自动获取
echo.
goto end
:end
@echo on
@pause
@dreulavelle
Copy link

English version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment