55 lines
1.4 KiB
Batchfile
55 lines
1.4 KiB
Batchfile
@echo off
|
|
chcp 65001 >nul
|
|
setlocal EnableExtensions EnableDelayedExpansion
|
|
|
|
set MODE=%1
|
|
set IFACE=%2
|
|
set IP=%3
|
|
set MASK=%4
|
|
set GW=%5
|
|
set DNS1=%6
|
|
set DNS2=%7
|
|
|
|
if /i "%MODE%"=="dhcp" goto dhcp
|
|
if /i "%MODE%"=="static" goto static
|
|
|
|
echo 1) DHCP
|
|
echo 2) Static
|
|
set /p MODESEL=Select mode [1/2]:
|
|
if "%MODESEL%"=="1" set MODE=dhcp
|
|
if "%MODESEL%"=="2" set MODE=static
|
|
|
|
if not defined IFACE set /p IFACE=Interface name [Ethernet]:
|
|
if "%IFACE%"=="" set IFACE=Ethernet
|
|
|
|
if /i "%MODE%"=="dhcp" goto dhcp
|
|
if /i "%MODE%"=="static" goto static
|
|
echo Invalid selection
|
|
exit /b 1
|
|
|
|
:dhcp
|
|
if not defined IFACE set /p IFACE=Interface name [Ethernet]:
|
|
if "%IFACE%"=="" set IFACE=Ethernet
|
|
netsh interface ip set address name="%IFACE%" source=dhcp
|
|
netsh interface ip set dns name="%IFACE%" source=dhcp
|
|
ipconfig /flushdns
|
|
echo Done
|
|
exit /b 0
|
|
|
|
:static
|
|
if not defined IFACE set /p IFACE=Interface name [Ethernet]:
|
|
if "%IFACE%"=="" set IFACE=Ethernet
|
|
if not defined IP set /p IP=IPv4 address:
|
|
if not defined MASK set /p MASK=Subnet mask:
|
|
if not defined GW set /p GW=Gateway:
|
|
if not defined DNS1 set /p DNS1=DNS1:
|
|
if not defined DNS2 set /p DNS2=DNS2 (optional):
|
|
netsh interface ip set address name="%IFACE%" static %IP% %MASK% %GW% 1
|
|
netsh interface ip set dns name="%IFACE%" static %DNS1% primary
|
|
if defined DNS2 netsh interface ip add dns name="%IFACE%" %DNS2% index=2
|
|
ipconfig /flushdns
|
|
echo Done
|
|
exit /b 0
|
|
|
|
|