Skip to content

Instantly share code, notes, and snippets.

@gufengxiaoyuehan
Last active April 27, 2018 04:30
Show Gist options
  • Save gufengxiaoyuehan/3afac9ebd3ed89ca03add542a8634aff to your computer and use it in GitHub Desktop.
Save gufengxiaoyuehan/3afac9ebd3ed89ca03add542a8634aff to your computer and use it in GitHub Desktop.
swtich between static ip address and dhcp
@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