Skip to main content

Batch script to change IP address details on a Windows Network Adapter - including a couple extra network related diagnostic features.

@echo off
@setlocal

title Multiple Choice Menu

:START
    set /p adapter=Network adapter name?:

:HOME
    echo.
    echo Select a task:
    echo =============
    echo.
    echo 1.^) Set Adapter to Static (COMTREND)
    echo 2.^) Set Adapter to Static (BEC)
    echo 3.^) Set Adapter to DHCP
    echo 4.^) Change Network Connection
    echo 5.^) Verify IP settings
    echo 6.^) Ping a host
    echo 7.^) Release/Renew IP, Flush DNS, Reset Winsock and Restart PC
    echo 8.^) Exit
    echo.

    set /p options=Type option:
    if "%options%"=="1" goto COMTREND
    if "%options%"=="2" goto BEC
    if "%options%"=="3" goto DHCP
    if "%options%"=="4" goto START
    if "%options%"=="5" goto VERIFY
    if "%options%"=="6" goto PINGHOST
    if "%options%"=="7" goto FLUSH
    if "%options%"=="8" exit

goto HOME

:COMTREND
    netsh interface ip set address name="%adapter%" static 192.168.1.100 255.255.255.0 192.168.1.1
    if %errorlevel% neq 0 exit /b 1
    rem netsh interface ip set dns name="%adapter%" static 192.168.1.1 primary
    goto HOME

:BEC
    netsh interface ip set address name="%adapter%" static 192.168.1.100 255.255.255.0 192.168.1.254
    if %errorlevel% neq 0 exit /b 1
    rem netsh interface ip set dns name="%adapter%" static 192.168.1.254 primary
    goto HOME

:DHCP
    netsh interface ip set address name="%adapter%" dhcp
    if %errorlevel% neq 0 exit /b 1
    netsh interface ip set dns name="%adapter%" dhcp
    if %errorlevel% neq 0 exit /b 1
    goto HOME

:VERIFY
    ipconfig
    if %errorlevel% neq 0 exit /b 1
    goto HOME

:PINGHOST
    set /p host=What host should we ping?:
    set /p count=How many times?:
    ping -n %count% %host%
    goto HOME

:FLUSH
    echo.Release/renew DHCP IP Address, Flush DNS records, Reset Winsock and Restart PC...
    ipconfig /release
    if %errorlevel% neq 0 exit /b 1
    ipconfig /renew
    if %errorlevel% neq 0 exit /b 1
    ipconfig /flushdns
    if %errorlevel% neq 0 exit /b 1
    netsh winsock reset
    if %errorlevel% neq 0 exit /b 1
    shutdown -r
    if %errorlevel% neq 0 exit /b 1

echo.
echo.Finished.

@endlocal
exit /b 0