做了一个切换内外网的小脚本。没想到这个老的没剩几颗牙的DOS竟然功能如此强大。盛名之下名副其实啊!不亏是想当年叱咤风云的操作系统啊!
脚本内容1.建立两个TXT文件,分别按行存储内外网的IP,MASK,GATEWAY,DNS F,DNS B,FOR循环的用法到现在也没吃透,网上找了很多资料,也仅仅是冰山一角的感觉。
2.建立后缀为.BAT的批处理文件,脚本内容如下
3.很笨拙的实现方式,有很大改善空间
@echo off
color f5
echo. :main
echo.
echo.
echo ======= 请按数字键选择(-):=======
echo.
choice /c /m "(1)=切换内网 (2)=切换外网 (3)=测试网络 (4)=退出" if errorlevel goto end
if errorlevel goto pingin
if errorlevel goto out
if errorlevel goto in :in
setlocal enabledelayedexpansion
set a=
set b=
set c=
set d=
set e=
for /f %%i in (内网IP.txt) do set /a a+= & if !a!== set ip=%%i
for /f %%i in (内网IP.txt) do set /a b+= & if !b!== set mask=%%i
for /f %%i in (内网IP.txt) do set /a c+= & if !c!== set gateway=%%i
for /f %%i in (内网IP.txt) do set /a d+= & if !d!== set dns1=%%i
for /f %%i in (内网IP.txt) do set /a e+= & if !e!== set dns2=%%i
echo %ip%
echo %mask%
echo %gateway%
echo %dns1%
echo %dns2%
goto runin %ip% %mask% %gateway% %dns1% %dns2% :out
setlocal enabledelayedexpansion
set a=
set b=
set c=
set d=
set e=
for /f %%i in (外网IP.txt) do set /a a+= & if !a!== set ip=%%i
for /f %%i in (外网IP.txt) do set /a b+= & if !b!== set mask=%%i
for /f %%i in (外网IP.txt) do set /a c+= & if !c!== set gateway=%%i
for /f %%i in (外网IP.txt) do set /a d+= & if !d!== set dns1=%%i
for /f %%i in (外网IP.txt) do set /a e+= & if !e!== set dns2=%%i
echo %ip%
echo %mask%
echo %gateway%
echo %dns1%
echo %dns2%
goto runin %ip% %mask% %gateway% %dns1% %dns2% :pingin
ping %dns1%
goto main :end
exit :runin
rem netsh interface ip set address name="本地连接" source=dhcp
rem ipconfig/flushdns
netsh interface ip set dns name="本地连接" source=dhcp
echo 正在更改IP地址为%......请稍后
netsh interface ip set address "本地连接" static %ip% %mask% %gateway% 1
echo IP地址修改成功!!!
echo 正在更改DNS地址为%......请稍后 netsh interface ip set dns name="本地连接" source=dhcp
netsh interface ip set dns name="本地连接" source=static addr=%dns1%
netsh interface ip add dns 本地连接 %dns2%
echo DNS地址修改成功!!!
goto main