detecting an internet connection

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
csb72
Newbie
Posts: 17
Joined: Thu Sep 20, 2007 6:21 am

detecting an internet connection

Post by csb72 » Mon Oct 01, 2007 8:18 pm

Hello everyone,

I've got a small challenge that I can't seem to figure out. So, perhaps one of you might take a look at it.

Here is the challenge. I have a program that requires an internet connection to work.

If their is an internet connection it opens and the ms script that I prepared earlier works fine.

BUT ...

If their is no internet connection every thing fails to work.

So, I figured I need an ms script that will detect if I have an internet connection first.

if internet connection ms script runs the rest of the script as normal.

if no internet connection it loops every 5 minutes until their is and then runs the rest of the ms script.

I've checked the forum and found the below rasdial posts. Unfortunately I am unable to get the rasdial to work.

Also, I am operating on a windows xp computer with a linksys lan connected to a cable modem. My lan also occasionally uses a wireless aircard through sprint pcs if the cable connection is unavailable.


Already attempted the two below:
---------------------------------------------
http://www.mjtnet.com/forum/viewtopic.p ... connection

which has this script within:

Let>RP_WAIT=1
Run>cmd.exe /c Rasdial >> %TEMP_DIR%\rasdial.txt
ReadFile>%TEMP_DIR%\rasdial.txt,ras
Position>No connections,ras,1,rp
If>rp>0
MessageModal>No Connection
Else
MessageModal>Connected
Endif
DeleteFile>%TEMP_DIR%\rasdial.txt
---------------------------------------------

and

---------------------------------------------
http://www.mjtnet.com/forum/viewtopic.p ... connection

which has this script within:

let>RP_WINDOWMODE=0
DeleteFile>c:\rasdial.txt
Run Program>cmd /c rasdial >c:\rasdial.txt
wait>0.5
Let>k=1
Label>start
ReadLn>c:\rasdial.txt,k,line
If>line=##EOF##,finish
rem Message>line
Let>k=k+1
Goto>start
Label>finish
if>k>3
MessageModal>Connection established
endif
---------------------------------------------

Thank you and make sure you have a fantastic day!
Carl

User avatar
JRL
Automation Wizard
Posts: 3529
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Mon Oct 01, 2007 8:38 pm

This is crude but it has worked for me from my home for several years. Although I ping my work computer rather than microsoft.

Code: Select all

Let>RP_WAIT=1
Run>cmd /c ping microsoft.com > %TEMP_DIR%InternetConnectTest
ReadFile>%TEMP_DIR%InternetConnectTest,file
DeleteFile>%TEMP_DIR%InternetConnectTest
Separate>file,Reply from,var
If>var_count>1,Connection_Available
MDL>No internet connection available
Goto>EOF
Label>Connection_Available
MDL>Internet connection available
Label>EOF

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Oct 01, 2007 8:39 pm

It's not really possible to detect an internet connection:
http://www.ndis.com/faq/QA05040101.htm

But you could just ping a known server and see if you get a response within a certain timeout.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

csb72
Newbie
Posts: 17
Joined: Thu Sep 20, 2007 6:21 am

Post by csb72 » Mon Oct 01, 2007 9:09 pm

I see ... (after reading the link you provided)

how would you recommend I use the ping with the time out? In other words, how would you write the ms script?

I truly don't know were to start.

Carl

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Oct 01, 2007 9:11 pm

Look four posts up.

But bear in mind this will cause some PCs to try to connect. That may not be an issue for you.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

csb72
Newbie
Posts: 17
Joined: Thu Sep 20, 2007 6:21 am

Post by csb72 » Mon Oct 01, 2007 9:23 pm

I don't know how I over looked JRL's post. I will test it immediately.

Thank you JRL.

Carl

csb72
Newbie
Posts: 17
Joined: Thu Sep 20, 2007 6:21 am

Post by csb72 » Mon Oct 01, 2007 9:48 pm

works beautifully!

Thank you JRL

Carl

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts