Sign in to follow this  
Followers 0
Xander

Fastest way to check for a web connection?

5 posts in this topic

Here's my best plan so far for a script to quickly determine whether it's got a connection. I thought about a Ping command but those can take a few seconds. I considered a InetGet'ting a small 1k file somewhere but that can have a delay ... so I'm looking to see if I can keep it strictly internal, letting the computer itself tell me if there's a connection.

Here's what I've got so far (AND IT WORKS), but I'd like to know if there are other/better ways.

(Can the "$ip...$web+1" lines be optimized as an array or something?)

Saved as an Include file "Checkweb.au3"

Func CheckWeb()
Local $ip,$web
$ip = StringLeft(@IPAddress1,7)
    if $ip="0.0.0.0" or $ip = "169.254" then $web=$web+1
$ip = StringLeft(@IPAddress2,7)
    if $ip="0.0.0.0" or $ip = "169.254" then $web=$web+1
$ip = StringLeft(@IPAddress3,7)
    if $ip="0.0.0.0" or $ip = "169.254" then $web=$web+1
$ip = StringLeft(@IPAddress4,7)
    if $ip="0.0.0.0" or $ip = "169.254" then $web=$web+1

If $web=4 then 
        Return "No";4 connections with no normal IP#
    else 
        Return "Yes"
    EndIf
EndFunc

Called within the other scripts:

#include checkweb.au3
$web=Checkweb()
if $web="yes" then ....;there is a connection

Share this post


Link to post
Share on other sites



Ping -n 1 127.0.0.1 will conduct a loopback test on a network and on a computer connected directly to the Internet.

the "-n 1" will only do the test once, returning only one test; probably 100 times faster this way.

Share this post


Link to post
Share on other sites

Ping -n 1 127.0.0.1  will conduct a loopback test on a network and on a computer connected directly to the Internet.

the "-n 1" will only do the test once, returning only one test; probably 100 times faster this way.

<{POST_SNAPBACK}>

Not sure I see an advantage to pinging a loopback address. Computers with no network cards or modems can ping that address successfully.

Otherwise, how would one incorporate the "-n 1" into a Ping() command? It seems to read as though that's the default.

Here's the result so far. Anybody foresee any problems?

Func CheckWeb()
If ping("64.233.161.104",200) >4 then  ;google.com
    Return "Yes";returns code of 4 or less if problems
    else 
        Return "No"  
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

I used the MS-DOS "Ping" command. An example below, on the Runwait() line

; Find_IP.au3
; Executes the MSDOS Ping command against a targeted Internet or Networked resource
; Ultimately returning only the I.P. Address of the target
; ----------------------------------------------------------------------------------
Local $strcomputer,$ip
$strcomputer = @computername
$strcomputer = InputBox("Display I.P. Address", "Enter the ComputerName for a remote PC, a web address, or press the {OK} button to show My_IP.", $strComputer, "")

; Ready to run the Ping, save the returned information to \Documents and Settings\[currentUser]\Find_IP.txt
RunWait(@ComSpec & " /C Ping -a -n 1 " & $strcomputer & "> Find_IP.txt",@MyDocumentsDir, @SW_HIDE)
$ip = FileRead(@MyDocumentsDir & "\Find_IP.txt", FileGetSize(@MyDocumentsDir & "\Find_IP.txt"))
FileDelete(@MyDocumentsDir & "\Find_IP.txt")

; Now lets look at all of the returned data...
MsgBox(0,"Returned Ping String [data]", "" & $ip)

; Lets search for the first occurance of "[.............]" and get rid of everything else
$ip = StringTrimLeft($ip, StringInStr($ip, "["))
$ip = StringLeft($ip, StringInStr($ip, "]")-1)

; Now, We will only return the I.P. address
MsgBox(0,"" & $strcomputer & " IP:", "" & $ip)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0