Last active
April 27, 2018 04:30
-
-
Save gufengxiaoyuehan/3afac9ebd3ed89ca03add542a8634aff to your computer and use it in GitHub Desktop.
swtich between static ip address and dhcp
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 | |
:: replace <xxx> with your configuration include "<" and ">" | |
setlocal enableextensions disabledelayedexpansion | |
set ip=<your staic ip> | |
set name=<your adapter name> | |
netsh interface ipv4 show addresses "%name%" | findstr /r /i /c:"ip.*%ip%$" >nul 2>nul | |
if errorlevel 1 ( | |
echo "current dynamic ip, swtich to %ip%" | |
netsh interface ip set address "%name%" static %ip% <subnet> <gateway> | |
netsh interface ip set dns "%name%" static <dns address> | |
) else ( | |
echo "current static ip <%ip%>, switch to %ip%" | |
netsh interface ip set address "%name%" dhcp | |
netsh interface ip set dns "%name%" dhcp ) | |
sleep 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment