bat文件设置ip自动和静态ip切换
下载地址:https://i.cnblogs.com/Files.aspx
win10系统:
@echo off cd /d %~dp0 %1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit title --IP自动设置 -- MODE con: COLS=80 lines=30 color 0a :begin @rem cls echo 要把IP设置为自动获取 请按 1 echo 要把IP设置为192.168.213.131 请按 2 echo 要把IP设置为192.168.1.13 请按 3 echo 要退出 请按 3 echo. choice /c 123450 /n /m " 请选择【1-3】:" echo %errorlevel% if %errorlevel% == 1 goto set_ip1_ip if %errorlevel% == 2 goto set_ip2_ip if %errorlevel% == 3 goto set_ip3_ip if %errorlevel% == 4 goto end if %times% == 0 (goto vpn_connect) else (goto begin) :set_ip1_ip echo IP自动设置开始.... echo. echo 自动获取IP地址.... netsh interface ip set address "以太网" dhcp echo 自动获取DNS服务器.... netsh interface ip set dns "以太网" dhcp @rem 设置自动获取IP echo 设置完成 pause goto end :set_ip2_ip echo IP自动设置开始.... echo. echo 正在设置IP及子网掩码 netsh interface ipv4 set address "以太网" "static" "192.168.213.131" "255.255.255.0" "192.168.213.1" "1" echo 设置DNS地址.... netsh interface ipv4 set dns "以太网" static 223.5.5.5 primary validate=no netsh interface ipv4 set dns "以太网" static 223.5.5.5 netsh interface ipv4 add dns "以太网" 114.114.114.114 echo 设置完成 pause goto end :set_ip3_ip echo IP自动设置开始.... echo. echo 正在设置IP及子网掩码 netsh interface ipv4 set address "以太网" "static" "192.168.213.131" "255.255.255.0" echo 设置完成 pause goto end :end exit
win7代码:
@echo off cd /d %~dp0 %1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&exit title --IP自动设置 -- MODE con: COLS=80 lines=30 color 0a :begin @rem cls echo 要把IP设置为自动获取 请按 1 echo 要把IP设置为192.168.2.198 请按 2 echo 要把IP设置为192.168.1.13 请按 3 echo 要退出 请按 3 echo. choice /c 123450 /n /m " 请选择【1-3】:" echo %errorlevel% if %errorlevel% == 1 goto set_ip1_ip if %errorlevel% == 2 goto set_ip2_ip if %errorlevel% == 3 goto set_ip3_ip if %errorlevel% == 4 goto end if %times% == 0 (goto vpn_connect) else (goto begin) :set_ip1_ip echo IP自动设置开始.... echo. echo 自动获取IP地址.... netsh interface ip set address name = "本地连接" source = dhcp echo 自动获取DNS服务器.... netsh interface ip set dns name = "本地连接" source = dhcp @rem 设置自动获取IP echo 设置完成 pause goto end :set_ip2_ip echo IP自动设置开始.... echo. echo 正在设置IP及子网掩码 cmd /c netsh interface ip set address name="本地连接" source=static addr=192.168.2.198 mask=255.255.255.0 gwmetric=1 echo 设置完成 pause goto end :set_ip3_ip echo IP自动设置开始.... echo. echo 正在设置IP及子网掩码 cmd /c netsh interface ip set address name="本地连接" source=static addr=192.168.1.13 mask=255.255.255.0 gwmetric=1 echo 设置完成 pause goto end :end exit