05/18/24 at 2:52pm  | YaBB Forum v2.3.1 
   
Advanced Search or try 30 Day QuickFetch ->
Page Index Toggle Pages: 1
Send Topic Print
OLDskool IPswitcher (Read 1446 times)
maddog
Site Administrator

Top Dog

*****
Offline


imo 'the goat'
Posts: 640
SW Lower Michigan, USA
Gender: male
OLDskool IPswitcher
04/29/18 at 12:51pm
 
Code:

:: mSQUARED (c)2018
@ECHO off

TITLE = OLDskool IPswitcher v18.04.30.0

SET AdapterName_01="Ethernet"
SET IPconfig_01=10.201.162.71 255.255.255.0 10.201.162.1
SET IPconfig_02=10.201.151.71 255.255.255.0 10.201.151.1

:: ----------------------------------------------------------------------------------------
:: Elevate privileges RUN AS ADMINISTRATOR
::
:: http://blog.spiralofhope.com?p=13553
:: https://stackoverflow.com/questions/7044985
:: http://stackoverflow.com/a/12264592/1190568
:checkPrivileges
NET FILE 1>NUL 2>NUL
if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
setlocal DisableDelayedExpansion
set "batchPath=%~0"
setlocal EnableDelayedExpansion
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\OEgetPrivileges.vbs"
ECHO args = "ELEV " >> "%temp%\OEgetPrivileges.vbs"
ECHO For Each strArg in WScript.Arguments >> "%temp%\OEgetPrivileges.vbs"
ECHO args = args ^& strArg ^& " " >> "%temp%\OEgetPrivileges.vbs"
ECHO Next >> "%temp%\OEgetPrivileges.vbs"
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%temp%\OEgetPrivileges.vbs"
"%SystemRoot%\System32\WScript.exe" "%temp%\OEgetPrivileges.vbs" %*
exit /B
:gotPrivileges
if '%1'=='ELEV' shift /1
setlocal & pushd .
cd /d %~dp0
:: ----------------------------------------------------------------------------------------

:start
CLS
ECHO -------------------
ECHO OLDskool IPswitcher
ECHO -------------------
netsh interface ip show address name=%AdapterName_01%
ECHO.
ECHO OPTIONS :
ECHO.
ECHO [1] - %AdapterName_01% IPv4 %IPconfig_01%
ECHO [2] - %AdapterName_01% IPv4 %IPconfig_02%
ECHO [3] - %AdapterName_01% IPv4 DHCP
ECHO [4] - Display %AdapterName_01% Current Configuration
ECHO [5] - Exit
ECHO.
SET choice=
SET /p choice=Enter selection . . .
IF NOT '%choice%'=='' SET choice=%choice:~0,1%
IF '%choice%'=='1' GOTO UserSelect1
IF '%choice%'=='2' GOTO UserSelect2
IF '%choice%'=='3' GOTO UserSelect3
IF '%choice%'=='4' GOTO start
IF '%choice%'=='5' GOTO end
ECHO.
PAUSE>NUL|SET/P =""%choice%" is not valid, press any key to continue . . . "
GOTO start

:UserSelect1
ECHO.
ECHO netsh interface ipv4 set address %AdapterName_01% static %IPconfig_01%
netsh interface ipv4 set address %AdapterName_01% static %IPconfig_01%
IF %ERRORLEVEL% NEQ 0 PAUSE
GOTO start

:UserSelect2
ECHO.
ECHO netsh interface ipv4 set address %AdapterName_01% static %IPconfig_02%
netsh interface ipv4 set address %AdapterName_01% static %IPconfig_02%
IF %ERRORLEVEL% NEQ 0 PAUSE
GOTO start

:UserSelect3
ECHO.
ECHO netsh interface ipv4 set address %AdapterName_01% dhcp
netsh interface ipv4 set address %AdapterName_01% dhcp
IF %ERRORLEVEL% NEQ 0 PAUSE
GOTO start

:end
EXIT
Back to top
« Last Edit: 05/17/18 at 12:51pm by maddog »  

~peace out - the maddog

...
Page Index Toggle Pages: 1
Send Topic Print
this board customized by maddog