Automatically run dial-up connection if DSL stops

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Automatically run dial-up connection if DSL stops

#1 Post by montanhani » 25 Oct 2012 08:51

Hello gentlemen,
I need to setup a dial-up connection to automatically starts with no interaction with the user when the DSL stops.
My computer is connected to a router, which is responsible to establish the DSL connection with the ISP.
I don't use the internet connection to navigate on the web, I'm not using a browser.
I have an application running on the background which needs the internet connection.

I'm trying to build a script that would ping an external website (i.e. www.google.com) and IF the ping is not successfull, it will trigger the dial-up connection.

Is this the best way to go?
Can anyone give me a suggestion?

Thanks a lot!

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Automatically run dial-up connection if DSL stops

#2 Post by abc0502 » 25 Oct 2012 09:17

ping the google website and post the message that appear when there is no connection like does it display time out or Destination host unreachable. or something like that.

ping using this command:

Code: Select all

ping www.google.com -n 1 -l 1

montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Re: Automatically run dial-up connection if DSL stops

#3 Post by montanhani » 25 Oct 2012 09:21

C:\Users\reggie>ping www.google.com -n 1 -l 1

Pinging www.google.com [173.194.37.82] with 1 bytes of data:
Request timed out.

Ping statistics for 173.194.37.82:
Packets: Sent = 1, Received = 0, Lost = 1 (100% loss),

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Automatically run dial-up connection if DSL stops

#4 Post by abc0502 » 25 Oct 2012 09:36

what windows do you use ? XP or 7

montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Re: Automatically run dial-up connection if DSL stops

#5 Post by montanhani » 25 Oct 2012 09:38

abc0502 wrote:what windows do you use ? XP or 7

I use Windows 7

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Automatically run dial-up connection if DSL stops

#6 Post by abc0502 » 25 Oct 2012 10:11

can you run this command in your cmd and till me the number that show in the begining of the line,
i'm trying to make my network show the same error but i can't

Code: Select all

For /F "tokens=* delims=" %a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:" Request timed out."') Do echo %a

montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Re: Automatically run dial-up connection if DSL stops

#7 Post by montanhani » 25 Oct 2012 10:19

abc0502 wrote:can you run this command in your cmd and till me the number that show in the begining of the line,
i'm trying to make my network show the same error but i can't

Code: Select all

For /F "tokens=* delims=" %a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:" Request timed out."') Do echo %a


It does not show anything when I run this command

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Automatically run dial-up connection if DSL stops

#8 Post by abc0502 » 25 Oct 2012 10:24

sorry, try this now:

Code: Select all

For /F "tokens=* delims=" %%a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:"Request timed out."') Do echo %%a


try it using a batch

montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Re: Automatically run dial-up connection if DSL stops

#9 Post by montanhani » 25 Oct 2012 10:32

abc0502 wrote:sorry, try this now:

Code: Select all

For /F "tokens=* delims=" %%a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:"Request timed out."') Do echo %%a


try it using a batch


This is what I got:

C:\Users\reggie>echo 3:Request timed out.
3:Request timed out.

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Automatically run dial-up connection if DSL stops

#10 Post by abc0502 » 25 Oct 2012 10:45

Ok that's what i have till now,

Code: Select all

@echo off & Color 0c

:loop
:: Check every 60 seconds
Ping localhost -n 60 >nul

setlocal enabledelayedexpansion
For /F "tokens=* delims=:" %%a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:"Request"') Do set "out=%%a"

IF "%out:~0,1%" equ "3" ( Goto Dail
) Else ( Goto loop )

:Dail
echo dail-up
pause
Exit /B

the batch check every 60 sec the connection, when it find that the out put of the ping command is Request timeout. it will go to the dail label where it will connect to the internet through the dail-up
if it didn't find the word it will go to the loop label where it will wait for another 60 sec and then check again

the problem now i never used a dail up connection so i don't know how to start the connection.
i found these to article, here and here

so try this commands
first get the name of the connection that uses the dsl and the dail
and try disconnecting the dsl like this:

Code: Select all

rasdial <dsl_connection_name> /disconnect

and do the same to the dail-up

then try to connect to dsl and dail by this:

Code: Select all

rasdial <dsl_connection_name> <user_name> <password>

montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Re: Automatically run dial-up connection if DSL stops

#11 Post by montanhani » 25 Oct 2012 10:49

abc0502 wrote:Ok that's what i have till now,

Code: Select all

@echo off & Color 0c

:loop
:: Check every 60 seconds
Ping localhost -n 60 >nul

setlocal enabledelayedexpansion
For /F "tokens=* delims=:" %%a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:"Request"') Do set "out=%%a"

IF "%out:~0,1%" equ "3" ( Goto Dail
) Else ( Goto loop )

:Dail
echo dail-up
pause
Exit /B

the batch check every 60 sec the connection, when it find that the out put of the ping command is Request timeout. it will go to the dail label where it will connect to the internet through the dail-up
if it didn't find the word it will go to the loop label where it will wait for another 60 sec and then check again

the problem now i never used a dail up connection so i don't know how to start the connection.
i found these to article, here and here

so try this commands
first get the name of the connection that uses the dsl and the dail
and try disconnecting the dsl like this:

Code: Select all

rasdial <dsl_connection_name> /disconnect

and do the same to the dail-up

then try to connect to dsl and dail by this:

Code: Select all

rasdial <dsl_connection_name> <user_name> <password>

We could connect to the dial-up by calling up another batch with the rasdial syntax.
How would the batch be then if we want to call this other batch (i.e. dial.bat) when the ping fails?

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Automatically run dial-up connection if DSL stops

#12 Post by abc0502 » 25 Oct 2012 10:52

you understand me wrong, we can add the connecing code under the dail label, but first test this command in your pc to see if they work or not

disconnect dsl

Code: Select all

rasdial <dsl_connection_name> /disconnect


connect dail-up

Code: Select all

rasdial <dail_connection_name> <user_name> <password>


if they work with you we will put them under the dail label in the above batch

montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Re: Automatically run dial-up connection if DSL stops

#13 Post by montanhani » 25 Oct 2012 10:56

abc0502 wrote:you understand me wrong, we can add the connecing code under the dail label, but first test this command in your pc to see if they work or not

disconnect dsl

Code: Select all

rasdial <dsl_connection_name> /disconnect


connect dail-up

Code: Select all

rasdial <dail_connection_name> <user_name> <password>


if they work with you we will put them under the dail label in the above batch

Ok, they actually work.
I've tried them before.
On my scenario, I don't need to disconnect the DSL because this connection is being handled by a router on the network.
What I just need is really to dial-up whenever the ping fails.
Thank you!

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Automatically run dial-up connection if DSL stops

#14 Post by abc0502 » 25 Oct 2012 11:00

Then this should work, give it a try

Code: Select all

@echo off & Color 0c

:loop
:: Check every 60 seconds
Ping localhost -n 60 >nul

setlocal enabledelayedexpansion
For /F "tokens=* delims=:" %%a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:"Request"') Do set "out=%%a"

IF "%out:~0,1%" equ "3" ( Goto Dail
) Else ( Goto loop )

:Dail
rasdial <dail_connection_name> <user_name> <password>

Exit /B


Replace the <dail_connection_name>, <user_name> and <password> with the real information between double quotes like "password" and the rest

montanhani
Posts: 12
Joined: 25 Oct 2012 08:44

Re: Automatically run dial-up connection if DSL stops

#15 Post by montanhani » 25 Oct 2012 11:37

abc0502 wrote:Then this should work, give it a try

Code: Select all

@echo off & Color 0c

:loop
:: Check every 60 seconds
Ping localhost -n 60 >nul

setlocal enabledelayedexpansion
For /F "tokens=* delims=:" %%a in ('Ping www.google.com -n 1 -l 1 ^|Findstr /I /N /C:"Request"') Do set "out=%%a"

IF "%out:~0,1%" equ "3" ( Goto Dail
) Else ( Goto loop )

:Dail
rasdial <dail_connection_name> <user_name> <password>

Exit /B


Replace the <dail_connection_name>, <user_name> and <password> with the real information between double quotes like "password" and the rest

It didn't work now because I got a different error message when trying to ping www.google.com

Code: Select all

C:\Users\reggie>ping www.google.com
Ping request could not find host www.google.com. Please check the name and try a
gain.

Post Reply