Created
May 21, 2013 05:05
-
-
Save mutoo/5617577 to your computer and use it in GitHub Desktop.
a batchfile for switching dhcp to static
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
cls | |
echo 开始获取动态IP :) | |
echo. | |
echo 正在设置自动获取IP地址... | |
netsh interface ip set address "本地连接" dhcp | |
echo 正在设置自动获取DNS... | |
netsh interface ip set dns "本地连接" dhcp | |
echo 正在更新IP... | |
ipconfig /renew "本地连接" > nul | |
echo. | |
echo 自动获取IP设置完成! | |
echo. | |
echo 正在测试连接性并等待连接建立: | |
ping www.baidu.com -n 10 | |
echo. | |
echo 当前获得的IP为: | |
for /f "tokens=3 delims= " %%i in ('netsh interface ip show config "本地连接" ^| find "IP"') do set ADDR=%%i | |
for /f "tokens=2 delims= " %%i in ('netsh interface ip show config "本地连接" ^| find "默认网关"') do set GWAY=%%i | |
echo %ADDR% | |
echo. | |
echo 开始将动态IP转换为静态IP... | |
echo. | |
echo 正在设置静态IP地址... | |
netsh interface ip set address "本地连接" static %ADDR% 255.255.255.0 %GWAY% | |
echo 正在设置主DNS服务器... | |
netsh interface ip set dns "本地连接" static 210.34.0.14 primary > nul | |
echo 正在设置备用DNS服务器... | |
netsh interface ip add dns "本地连接" 210.34.0.18 > nul | |
echo 静态IP设置完成! | |
echo. | |
echo 正在测试测试连接性: | |
ping %GWAY% -n 10 | |
echo. | |
echo IP转换完成。 | |
echo. | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment