windows 7和WIN 10如何通过电脑bat一键设置IP和DNS,有了这个小技巧,就可以一键切换。懒人必备!
windows 7代码如下:
@echo off
echo ┌────────────────────────────┐
echo | |
echo | 切换网络环境,请输入当前所在位置 QQ:431228450│
echo | |
echo | 小辉网络工作室 (www.8gws.com) |
echo | |
echo | 网站宗旨:学习使我快乐,分享让我感到助人为乐的更快乐 |
echo | |
echo └────────────────────────────┘
echo ===========================================
echo 操作说明:请选择要进行的操作,然后按回车
echo ===========================================
echo.
echo 1.修改ip为外网动态ip
echo.
echo 2.恢复ip为内网静态ip
echo.
echo 请输入1或者2按ENTER回车键确认!
echo.
echo.
echo.
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:choice
set choice=
set /p choice=请输入1或者2:
if %choice%==2 goto school_lan
if %choice%==1 (goto lab_lan) else (echo 输入错误,请重新输入&goto choice)
:lab_lan
set eth="本地连接"
set ip=192.168.0.10
set netmask=255.255.255.0
set gw=192.168.0.1
set dns1=114.114.114.114
set dns2=8.8.8.8
echo.
echo 切换到外网有线环境
echo.
goto switch
:school_lan
set eth="本地连接"
set ip=192.168.0.245
set netmask=255.255.255.0
set gw=192.168.0.254
set dns1=202.103.44.150
set dns2=202.103.24.68
echo.
echo 切换到内网环境
echo.
goto switch
:switch
set code=
set /p code= 你的IP主机号 %ip%
set "ip=%ip%%code%"
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% register=PRIMARY validate=no
if defined dns2 (
echo 正在设置备用DNS服务器 %dns2%
netsh interface ip add dns %eth% %dns2% index=2 validate=no
)
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
win10 代码如下:
@echo off
echo ┌────────────────────────────┐
echo | |
echo | 切换网络环境,请输入当前所在位置 QQ:431228450│
echo | |
echo | 小辉网络工作室 (www.8gws.com) |
echo | |
echo | 网站宗旨:学习使我快乐,分享让我感到助人为乐的更快乐 |
echo | |
echo └────────────────────────────┘
echo ===========================================
echo 操作说明:请选择要进行的操作,然后按回车
echo ===========================================
echo.
echo 1.修改ip为内网ip,静态IP
echo.
echo 2.恢复ip为动态ip,并关闭代理
echo.
echo 0.退出
echo.
echo.
echo.
:loop_start
set /p choice= 请选择:
IF NOT "%choice%"=="" SET choice=%choice:~0,1%
if /i "%choice%"=="1" goto set_start
if /i "%choice%"=="2" goto reset_start
if /i "%choice%"=="0" goto closee
echo 选择无效,请重新输入
echo.
goto loop_start
::====================================================================================
:set_start
echo 设置IP地址....
netsh interface ip set addr "以太网" static 192.168.0.239 255.255.255.0 192.168.0.254
echo 设置DNS地址....
netsh interface ip set dns "以太网" static 202.103.44.150 primary validate=no
netsh interface ip add dns name="以太网" addr=202.103.24.68
echo *****设置成功!您的IP已修改为内网ip
echo.
goto endd
::====================================================================================
:reset_start
echo 恢复IP地址....
netsh interface ip set addr "以太网" dhcp
echo 恢复DNS地址....
netsh interface IP set dns "以太网" dhcp
echo *****设置成功!您的IP已恢复为动态ip
echo.
echo 正在清空代理服务器设置……
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "" /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "" /f
echo.
echo *****设置成功!代理服务器设置已经清空
echo.
goto endd
::====================================================================================
:endd
pause
:closee