-
Notifications
You must be signed in to change notification settings - Fork 1
/
autoIPsetter.bat
86 lines (86 loc) · 3.25 KB
/
autoIPsetter.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@echo off
REM LABA
CLS
ECHO.
ECHO =============================
ECHO AUTO IP CONFIGURATOR
ECHO =============================
REM ----------PRESET SETTINGS-------
set varIP=10.0.80.50
REM WRITE YOUR COMPUTER IP ABOVE
set varDefaultGateway=10.0.80.1
set varSubnetMask=255.255.255.192
set varPrimaryDNS=4.2.2.2
set varSecondaryDNS=8.8.8.8
REM --------------------------------
:init
setlocal DisableDelayedExpansion
set cmdInvoke=1
set winSysFolder=System32
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
setlocal EnableDelayedExpansion
: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)
ECHO.
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = "ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
if '%cmdInvoke%'=='1' goto InvokeCmd
ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
goto ExecElevation
:InvokeCmd
ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"
:ExecElevation
"%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & cd /d %~dp0
if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
::::::::::::::::::::::::::::
::START
::::::::::::::::::::::::::::
REM Run shell as admin
@echo off
REM LABA
for /F "usebackq skip=1 tokens=2" %%a in ("%~F0") do set "BOOLEAN_VALUE=%%a" & goto continue
:continue
TITLE Automatically setting IP for %BOOLEAN_VALUE%
ECHO BOOLEAN_VALUE=%BOOLEAN_VALUE%
IF %BOOLEAN_VALUE% EQU GHAR GOTO 2
:1
netsh interface ip set address name="Ethernet" static %varIP% %varSubnetMask% %varDefaultGateway%
netsh interface ip set dnsservers name="Ethernet" source=static address=%varPrimaryDNS% register=primary
netsh interface ip add dns name="Ethernet" address=%varSecondaryDNS%
GOTO UPDATE_BOOLEAN_VALUE
:2
netsh interface ipv4 set address name="Ethernet" source=dhcp
netsh interface ip set dnsservers name="Ethernet" source=dhcp
:UPDATE_BOOLEAN_VALUE
REM The code to change the BOOLEAN_VALUE i.e. a toggler
if %BOOLEAN_VALUE% equ GHAR (set "BOOLEAN_VALUE=LABA") else set "BOOLEAN_VALUE=GHAR"
(
echo @echo off
echo REM %BOOLEAN_VALUE%
for /F "usebackq skip=2 delims=" %%a in ("%~F0") do echo %%a
) > _new_.bat
move /Y _new_.bat "%~F0" > NUL
if %BOOLEAN_VALUE% equ GHAR (set "BOOLEAN_VALUE=LABA") else set "BOOLEAN_VALUE=GHAR"
echo Setting applied for:: %BOOLEAN_VALUE%
pause
exit
REM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM :: Get here: https://github.com/siddhantrimal/auto-IP-changer
REM :: built with Elevate.cmd - Version 4
REM :: Automatically check & get admin rights
REM :: referenced from: http://stackoverflow.com/a/12264592/5040900
REM :: modified by Siddhant-Rimal 03-16-2017 v.1.0
REM :: enhanced by Siddhant-Rimal 11-16-2017 v.1.1
REM ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::