Skip to content

Instantly share code, notes, and snippets.

@jimdiroffii
Created September 14, 2020 14:58
Show Gist options
  • Save jimdiroffii/da41ebf0d40b97f86337c7f12bac8bc5 to your computer and use it in GitHub Desktop.
Save jimdiroffii/da41ebf0d40b97f86337c7f12bac8bc5 to your computer and use it in GitHub Desktop.
Interactively set an IP address in the CMD line of Windows
@echo off
echo Choose:
echo [A] Set Static IP
echo [B] Set DHCP
echo.
:choice
SET /P C=[A,B]?
for %%? in (A) do if /I "%C%"=="%%?" goto A
for %%? in (B) do if /I "%C%"=="%%?" goto B
goto choice
:A
echo Please enter Static IP Address Information
echo Static IP Address:
set /p IP_Addr=
echo Default Gateway:
set /p D_Gate=
echo Subnet Mask:
set /p Sub_Mask=
echo Primary DNS:
set /p P_DNS=
echo Secondary DNS:
set /p S_DNS=
echo Setting Static IP Information
netsh interface ip set address "LAN" static %IP_Addr% %Sub_Mask% %D_Gate% 1
netsh interface ip set dnsservers name="LAN" static %P_DNS%
netsh interface ip set dnsservers name="LAN" static %S_DNS% index=2
ECHO Here are the new settings for %computername%:
netsh int ip show config
pause
goto end
:B
ECHO Resetting IP Address and Subnet Mask For DHCP
netsh interface ip set address name = "LAN" source = dhcp
netsh interface ip set dnsservers name="LAN" source = dhcp
ipconfig /release
ipconfig /renew
ECHO Here are the new settings for %computername%:
netsh int ip show config
pause
goto end
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment