Skip to content

Instantly share code, notes, and snippets.

@joshhodgson
Last active August 8, 2017 15:28
Show Gist options
  • Save joshhodgson/85ca5093c220f0622fe9ac65bfadd554 to your computer and use it in GitHub Desktop.
Save joshhodgson/85ca5093c220f0622fe9ac65bfadd554 to your computer and use it in GitHub Desktop.
Windows batch file to edit the Ethernet port IP address quickly and without repeated authentication popups.
@echo off
:start
cls
netsh interface ip show address name="Local Area Connection"
echo.
echo.
echo.
set INPUT=
echo Enter 's' to set static IP, 'd' to enable DHCP, or 'q' to quit
set /p INPUT=Type input: %=%
If "%INPUT%"=="s" goto static
If "%INPUT%"=="d" goto dhcp
If "%INPUT%"=="q" goto end
echo "Input not recognised" & goto start
:static
cls
echo Setting static IP
echo.
set IP=
set SUBNET=255.255.255.0
set /p IP=Enter IP Address:%=%
echo.
set /p SUBNET=Enter Subnet Mask (leave blank for 255.255.255.0): %=%
echo.
echo You entered IP %IP% and subnet mask %SUBNET%
netsh interface ip set address name="Local Area Connection" source=static addr=%IP% mask=%SUBNET%
ping -n 4 127.0.0.1 > nul
pause
goto start
:dhcp
cls
echo Setting DHCP
netsh interface ip set address name="Local Area Connection" source=dhcp
netsh interface ip set dns name="Local Area Connection" source=dhcp
pause
goto start
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment