Testing internet connection using HTTPREQUEST>

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
Roberto F.
Newbie
Posts: 2
Joined: Fri Jun 20, 2014 1:10 pm

Testing internet connection using HTTPREQUEST>

Post by Roberto F. » Fri Jun 20, 2014 1:26 pm

Hi friends,

I was trying to make a code to test internet connection, more reliable then "IsConnectedToInternet>".

First I tryed to use ping to do this, but failed to find any URL tha responds to it....

So, I wrote a simple code to do the job using HTTPREQUEST and I want to share with you:

Code: Select all

HTTPRequest>http://www.google.com,,GET,,strHTML,,,,
RegEx>404 Error connecting to host,strHTML,1,connection,num,0
IF>connection_1=404 Error connecting to host
    MessageModal>NOT CONNECTED...
ELSE
    MessageModal>CONNECTED!
ENDIF
Very fast when there is an internet connection. Takes a few seconds when internet is down.
Simple, but works. If someone has a better code, please let me know :wink:

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Testing internet connection using HTTPREQUEST>

Post by CyberCitizen » Sat Jun 21, 2014 1:07 am

I have something similar.

Been having issues with my connection where there is no data throughput although it still shows as connected. A restart of the router fixes this issue, the Internet provider has been doing some work to try and resolve this issue, however this was put in place as a work around in the mean time so I can SSH remotely. When the connection is screwed I can't SSH or connect to the machine, pain in the ass when I am at work etc.

I have the script compiled and in the startup folder so it runs when ever the machine is online.

// COMPILE_OPTS|C:\Downloads\Usenet\Restart Router Agent v1.2.exe|M:\Icons\network_driver_offline.ico|CONSOLE=0|INCLUDES=1| /LOGFILE=\dev\nul /NOSYSTRAY /HIDE|RUNTIMES=1|BMPS=1
ExtractFileName>Command_Line,strFileName
ExtractFileExt>Command_Line,strExt
StringReplace>%strFileName%,",,strFileName
StringReplace>%strExt%,",,strExt
StringReplace>%strFileName%,%strExt%,,strFileName
Trim>%strFileName%,strFileName
Let>APP_TITLE=%strFileName%

Label>Start
Let>HTTP_TIMEOUT=15
HTTPRequest>http://checkip.dyndns.com,,GET,,vHTML,,,,
If>%vHTML%=404 Error connecting to host
Let>vHTML={""}
Wait>15
HTTPRequest>http://www.google.com.au,,GET,,vHTML,,,,
If>%vHTML%=404 Error connecting to host
Let>ASK_TIMEOUT=30000
Ask>Loss Of Internet Connectivity Detected%CRLF%Do You Want Me To Restart The Router?%CRLF%%CRLF%Allow 2 Minutes For The Router To Restart.,vResponse
If>%vResponse%=YES
GoSub>sRestartRouter
Wait>300
GoSub>sNotifyMyAndroid
EndIf
EndIf
EndIf
Wait>90
Let>vHTML={""}
Goto>Start

SRT>sRestartRouter
Let>vPostData=factory=E0
HTTPRequest>http://XXXX:[email protected]/reset/,,POST,,vHTML,,,,
END>sRestartRouter

SRT>sNotifyMyAndroid
GetDate>vDate
GetTime>vTime
TimeAdd>vTime,M,-5,vTime
Let>URL=application=%APP_TITLE%&event=Loss Of Connectivity Detected&description=Router Restarted At %vTime% On The %vDate%.
StringReplace>%URL%,%SPACE%,%20,URL
HTTPRequest>http://www.notifymyandroid.com/publicap ... HTMLResult,,
Label>lWriteInfo
IfDirExists>C:\Temp
WriteLn>C:\Temp\%APP_TITLE%.txt,Result,[Date]%CRLF%· %vDate%%CRLF%[Time]%CRLF%· %vTime%%CRLF%[Application]%CRLF%· %APP_TITLE%%CRLF%[Event]%CRLF%· Loss Of Connectivity Detected%CRLF%[Description]%CRLF%· Router Restarted At %vTime% On The %vDate%.%LF%
Else
CreateDir>C:\Temp
Goto>lWriteInfo
EndIf
END>sNotifyMyAndroid

  View Snippet Page
FIREFIGHTER

Roberto F.
Newbie
Posts: 2
Joined: Fri Jun 20, 2014 1:10 pm

Re: Testing internet connection using HTTPREQUEST>

Post by Roberto F. » Sat Jun 21, 2014 2:29 pm

CyberCitizen, thank you!

Your code helped me to fix another problem I had: NotifyMyAndroid code. :D

I forgot to use "%20" on spaces and it was not working without this action.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Testing internet connection using HTTPREQUEST>

Post by CyberCitizen » Sat Jun 21, 2014 3:00 pm

Happy to have assisted.
FIREFIGHTER

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