Rasdial and advanced batch file scripting.

w1z4rd

Karmic Sangoma
Joined
Jan 17, 2005
Messages
52,146
Reaction score
8,340
Location
127.0.0.1
Basically the Windows dialer is pretty useless and having used Linux so much I am very comfy in command line. So I was wondering if anyone here could help me advance a script I have put together through googling.

Sometimes like with all towers the connection goes down for a couple of minutes... often due to tropical storms in this neck of the woods.

1)What I want the script to do is use rasdial to connect to my Internet provider.

2) If connection was successful to confirm that there is an active Internet connection.

3) If there either of those fail then it is to retry until it gets an active working connection.

4) To check that the internet has not stalled every 30 min or so.

5) If it has stalled (ie you are still connected but there is no data going through), to disconnect and start again.

In the scripting below I think I have got numbers 1 to 3 waxed... does anyone know how to had 4 and 5?

Other info: The rasdial disconnection command is : rasdial "Connection name" /DISCONNECT

The script:
@ECHO OFF

:loop
Echo Trying to connect to Sun Broadband Standard...
rasdial "Sun Broadband Standard"

ping www.google.com

if NOT %ERRORLEVEL% ==0 goto failed

Exit
:failed

Echo Failed to connect. Sun Cellular are retarded.

goto loop

Its a bit dirty because of the exit command... It closes the window when it connects which I dont really want it to do. Is there a way for it to simply break the loop without it exiting command prompt?
 
Last edited:
Try use AutoIT to create batch file, it is simple to use: http://www.autoitscript.com/autoit3/. Also try look at KIX, its pretty cool....

Why is there an exit statement?

For 4, try use the Wait command, it will wait a certain period of time and then proceed. KIX has the wait command built into the compiler, else you can download it.


@ECHO OFF

:loop
Echo Trying to connect to Sun Broadband Standard...
rasdial "Sun Broadband Standard"

ping www.google.com

if NOT %ERRORLEVEL% ==0 goto failed

wait 30

goto loop

:failed

Echo Failed to connect. Sun Cellular are retarded.
 
C:\Users\Owner>wait 10
'wait' is not recognized as an internal or external command,
operable program or batch file.

Seems like wait is no longer an option.

The exit command is there so that the script doesnt continue trying to dial and ping if the conditions are met. If you remove the exit command it dials continues saying there is already an active connection and just loops like that to infinity.
 
Its a bit dirty because of the exit command... It closes the window when it connects which I dont really want it to do. Is there a way for it to simply break the loop without it exiting command prompt?

Try adding a 'pause' command before the 'exit'. It will ask you to 'Press any key to continue' and the window will stay open .
 
You can use the cheap and dirty sleep if you want to use a batch script:

PING 1.0.0.0 –n 1 –w 1000 > NUL

1000 represents the time. This is obviously not ideal so you want to download sleep http://www.sleepcmd.com/sleep.zip Remember to scan it for viruses first, as I have not tested it.
 
Seems like wait is no longer an option.

The exit command is there so that the script doesnt continue trying to dial and ping if the conditions are met. If you remove the exit command it dials continues saying there is already an active connection and just loops like that to infinity.

Put :end at the end of the file and goto end

You can use the cheap and dirty sleep if you want to use a batch script:

PING 1.0.0.0 –n 1 –w 1000 > NUL

1000 represents the time. This is obviously not ideal so you want to download sleep http://www.sleepcmd.com/sleep.zip Remember to scan it for viruses first, as I have not tested it.

-n would be the number of seconds it 'sleeps' for

For 4 and 5:
ping www.google.com |find "Lost" >outputfile
FOR /F "tokens=10" %%i IN (outputfile) DO IF %%i GTR 2 rasdial (delete connection) && rasdial (start connection)
If the number of packets lost is greater than 2 (out of the default 4) then it will disconnect and reconnect. Replace (delete connection) and (start connection) with appropriate switches and connection names.
Edit: and use rasphone instead of rasdial :D
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X