Apr 25, 2013

Enhanced script to modify the Windows default route

[ for the complete story check the post Modify Windows default route with a script when connecting to wifi ]


@ECHO OFF
ECHO This script will change the wireless connection routing.
set /p runScript=Do you really want to run the script now [y/n]?:

:UINTERACTION
IF "%runScript%"=="y" GOTO ROUTEMAN
IF "%runScript%"=="n" GOTO End
set /p runScript=You need to answer with "y" or "n":
GOTO UINTERACTION


:ROUTEMAN
route delete 0.0.0.0 MASK 0.0.0.0 192.168.1.1

ping -a myipaddress.dyndns.org -n 1 > testresult.tmp
for /f "tokens=2  delims=[" %%G IN (testresult.tmp) DO echo %%G > testresult.tmp
for /f "tokens=1  delims=]" %%G IN (testresult.tmp) DO ( echo address for myipaddress.dyndns.org is: %%G

del testresult.tmp


REM add route for myipaddress.dyndns.org
echo address for myipaddress.dyndns.org is: %remoteIP%
route add %%G mask 255.255.255.255 192.168.1.1 )
tracert -h 2 myipaddress.dyndns.org
GOTO End

:END

No comments:

Post a Comment