Jump to content

If ping return > 0 does not mean connected, then what does ?


Recommended Posts

All good points.

For DNS problems, I've often solved them by running "ipconfig /flushdns"

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

When using this script to check for local ip's

Global $sPath = @ScriptDir & "\Scanned IPs.txt"

_Scan()

Func _Scan()
    Local $aSplit = StringSplit(@IPAddress1, ".")
    Local $sIP = $aSplit[1] & "." & $aSplit[2] & "." & $aSplit[3] & "."
    Local $aValidIPs[256], $iIndex = 0, $sValidIPs

    If (FileExists($sPath)) Then FileDelete($sPath)

    FileWrite($sPath, "IP,            Error,        Result" & @CRLF)
    For $i = 0 To 256
        $iResult = Ping($sIP & $i, 500)

        If ($iResult >= 1) Then
            $aValidIPs[$iIndex] = $sIP & $i
            $sValidIPs &= $sIP & $i & @CRLF
            $iIndex += 1
        EndIf

        FileWrite($sPath, "" & $sIP & $i & "        " & @error & "        " & $iResult & @CRLF)
    Next

    ReDim $aValidIPs[$iIndex]
    FileWrite($sPath, @CRLF & @CRLF & "IP's with result >= 1" & @CRLF & $sValidIPs)
EndFunc

It wrote this file

IP,            Error,        Result
xxx.xxx.xxx.0        1        0
xxx.xxx.xxx.1        0        1
xxx.xxx.xxx.2        1        0
xxx.xxx.xxx.3        1        0
xxx.xxx.xxx.4        1        0
xxx.xxx.xxx.5        1        0
xxx.xxx.xxx.6        1        0
xxx.xxx.xxx.7        0        1
xxx.xxx.xxx.8        1        0
xxx.xxx.xxx.9        1        0
xxx.xxx.xxx.10        1        0
xxx.xxx.xxx.11        1        0
xxx.xxx.xxx.12        1        0
xxx.xxx.xxx.13        1        0
xxx.xxx.xxx.14        1        0
xxx.xxx.xxx.15        1        0
xxx.xxx.xxx.16        0        1
xxx.xxx.xxx.17        1        0
xxx.xxx.xxx.18        1        0
xxx.xxx.xxx.19        1        0
xxx.xxx.xxx.20        1        0
xxx.xxx.xxx.21        1        0
xxx.xxx.xxx.22        1        0
xxx.xxx.xxx.23        1        0
xxx.xxx.xxx.24        0        1
xxx.xxx.xxx.25        1        0
xxx.xxx.xxx.26        0        189
xxx.xxx.xxx.27        0        1
xxx.xxx.xxx.28        0        302
xxx.xxx.xxx.29        0        1
xxx.xxx.xxx.30        1        0
xxx.xxx.xxx.31        0        1
xxx.xxx.xxx.32        0        1
xxx.xxx.xxx.33        1        0
xxx.xxx.xxx.34        0        1
xxx.xxx.xxx.35        0        1
xxx.xxx.xxx.36        1        0
xxx.xxx.xxx.37        1        0
xxx.xxx.xxx.38        0        2
xxx.xxx.xxx.39        0        305
xxx.xxx.xxx.40        0        1
xxx.xxx.xxx.41        1        0
xxx.xxx.xxx.42        1        0
xxx.xxx.xxx.43        1        0
xxx.xxx.xxx.44        1        0
xxx.xxx.xxx.45        1        0
xxx.xxx.xxx.46        1        0
xxx.xxx.xxx.47        0        161
xxx.xxx.xxx.48        1        0
xxx.xxx.xxx.49        1        0
xxx.xxx.xxx.50        1        0
xxx.xxx.xxx.51        1        0
xxx.xxx.xxx.52        1        0
xxx.xxx.xxx.53        0        1
xxx.xxx.xxx.54        0        1
xxx.xxx.xxx.55        1        0
xxx.xxx.xxx.56        0        294
xxx.xxx.xxx.57        1        0
xxx.xxx.xxx.58        1        0
xxx.xxx.xxx.59        1        0
xxx.xxx.xxx.60        1        0
xxx.xxx.xxx.61        1        0
xxx.xxx.xxx.62        0        208
xxx.xxx.xxx.63        0        1
xxx.xxx.xxx.64        1        0
xxx.xxx.xxx.65        1        0
xxx.xxx.xxx.66        1        0
xxx.xxx.xxx.67        1        0
xxx.xxx.xxx.68        1        0
xxx.xxx.xxx.69        1        0
xxx.xxx.xxx.70        1        0
xxx.xxx.xxx.71        1        0
xxx.xxx.xxx.72        1        0
xxx.xxx.xxx.73        1        0
xxx.xxx.xxx.74        1        0
xxx.xxx.xxx.75        1        0
xxx.xxx.xxx.76        1        0
xxx.xxx.xxx.77        1        0
xxx.xxx.xxx.78        1        0
xxx.xxx.xxx.79        1        0
xxx.xxx.xxx.80        1        0
xxx.xxx.xxx.81        1        0
xxx.xxx.xxx.82        1        0
xxx.xxx.xxx.83        1        0
xxx.xxx.xxx.84        1        0
xxx.xxx.xxx.85        1        0
xxx.xxx.xxx.86        1        0
xxx.xxx.xxx.87        1        0
xxx.xxx.xxx.88        1        0
xxx.xxx.xxx.89        1        0
xxx.xxx.xxx.90        1        0
xxx.xxx.xxx.91        1        0
xxx.xxx.xxx.92        1        0
xxx.xxx.xxx.93        1        0
xxx.xxx.xxx.94        1        0
xxx.xxx.xxx.95        1        0
xxx.xxx.xxx.96        1        0
xxx.xxx.xxx.97        0        1
xxx.xxx.xxx.98        1        0
xxx.xxx.xxx.99        1        0
xxx.xxx.xxx.100        0        1
xxx.xxx.xxx.101        1        0
xxx.xxx.xxx.102        1        0
xxx.xxx.xxx.103        0        1
xxx.xxx.xxx.104        1        0
xxx.xxx.xxx.105        1        0
xxx.xxx.xxx.106        1        0
xxx.xxx.xxx.107        1        0
xxx.xxx.xxx.108        1        0
xxx.xxx.xxx.109        1        0
xxx.xxx.xxx.110        1        0
xxx.xxx.xxx.111        1        0
xxx.xxx.xxx.112        1        0
xxx.xxx.xxx.113        1        0
xxx.xxx.xxx.114        1        0
xxx.xxx.xxx.115        1        0
xxx.xxx.xxx.116        1        0
xxx.xxx.xxx.117        1        0
xxx.xxx.xxx.118        1        0
xxx.xxx.xxx.119        1        0
xxx.xxx.xxx.120        1        0
xxx.xxx.xxx.121        1        0
xxx.xxx.xxx.122        1        0
xxx.xxx.xxx.123        1        0
xxx.xxx.xxx.124        1        0
xxx.xxx.xxx.125        1        0
xxx.xxx.xxx.126        1        0
xxx.xxx.xxx.127        1        0
xxx.xxx.xxx.128        1        0
xxx.xxx.xxx.129        1        0
xxx.xxx.xxx.130        1        0
xxx.xxx.xxx.131        1        0
xxx.xxx.xxx.132        1        0
xxx.xxx.xxx.133        1        0
xxx.xxx.xxx.134        1        0
xxx.xxx.xxx.135        1        0
xxx.xxx.xxx.136        1        0
xxx.xxx.xxx.137        1        0
xxx.xxx.xxx.138        1        0
xxx.xxx.xxx.139        1        0
xxx.xxx.xxx.140        1        0
xxx.xxx.xxx.141        1        0
xxx.xxx.xxx.142        1        0
xxx.xxx.xxx.143        1        0
xxx.xxx.xxx.144        1        0
xxx.xxx.xxx.145        1        0
xxx.xxx.xxx.146        1        0
xxx.xxx.xxx.147        1        0
xxx.xxx.xxx.148        1        0
xxx.xxx.xxx.149        1        0
xxx.xxx.xxx.150        1        0
xxx.xxx.xxx.151        1        0
xxx.xxx.xxx.152        1        0
xxx.xxx.xxx.153        1        0
xxx.xxx.xxx.154        1        0
xxx.xxx.xxx.155        1        0
xxx.xxx.xxx.156        1        0
xxx.xxx.xxx.157        1        0
xxx.xxx.xxx.158        1        0
xxx.xxx.xxx.159        1        0
xxx.xxx.xxx.160        1        0
xxx.xxx.xxx.161        1        0
xxx.xxx.xxx.162        1        0
xxx.xxx.xxx.163        1        0
xxx.xxx.xxx.164        1        0
xxx.xxx.xxx.165        1        0
xxx.xxx.xxx.166        1        0
xxx.xxx.xxx.167        1        0
xxx.xxx.xxx.168        1        0
xxx.xxx.xxx.169        1        0
xxx.xxx.xxx.170        1        0
xxx.xxx.xxx.171        1        0
xxx.xxx.xxx.172        1        0
xxx.xxx.xxx.173        1        0
xxx.xxx.xxx.174        1        0
xxx.xxx.xxx.175        1        0
xxx.xxx.xxx.176        1        0
xxx.xxx.xxx.177        1        0
xxx.xxx.xxx.178        1        0
xxx.xxx.xxx.179        1        0
xxx.xxx.xxx.180        1        0
xxx.xxx.xxx.181        1        0
xxx.xxx.xxx.182        1        0
xxx.xxx.xxx.183        1        0
xxx.xxx.xxx.184        1        0
xxx.xxx.xxx.185        1        0
xxx.xxx.xxx.186        1        0
xxx.xxx.xxx.187        1        0
xxx.xxx.xxx.188        1        0
xxx.xxx.xxx.189        1        0
xxx.xxx.xxx.190        1        0
xxx.xxx.xxx.191        1        0
xxx.xxx.xxx.192        1        0
xxx.xxx.xxx.193        1        0
xxx.xxx.xxx.194        1        0
xxx.xxx.xxx.195        1        0
xxx.xxx.xxx.196        1        0
xxx.xxx.xxx.197        1        0
xxx.xxx.xxx.198        1        0
xxx.xxx.xxx.199        1        0
xxx.xxx.xxx.200        1        0
xxx.xxx.xxx.201        1        0
xxx.xxx.xxx.202        1        0
xxx.xxx.xxx.203        1        0
xxx.xxx.xxx.204        1        0
xxx.xxx.xxx.205        1        0
xxx.xxx.xxx.206        1        0
xxx.xxx.xxx.207        1        0
xxx.xxx.xxx.208        1        0
xxx.xxx.xxx.209        1        0
xxx.xxx.xxx.210        1        0
xxx.xxx.xxx.211        1        0
xxx.xxx.xxx.212        1        0
xxx.xxx.xxx.213        1        0
xxx.xxx.xxx.214        1        0
xxx.xxx.xxx.215        1        0
xxx.xxx.xxx.216        1        0
xxx.xxx.xxx.217        1        0
xxx.xxx.xxx.218        1        0
xxx.xxx.xxx.219        1        0
xxx.xxx.xxx.220        0        5
xxx.xxx.xxx.221        1        0
xxx.xxx.xxx.222        1        0
xxx.xxx.xxx.223        1        0
xxx.xxx.xxx.224        1        0
xxx.xxx.xxx.225        1        0
xxx.xxx.xxx.226        1        0
xxx.xxx.xxx.227        1        0
xxx.xxx.xxx.228        1        0
xxx.xxx.xxx.229        1        0
xxx.xxx.xxx.230        1        0
xxx.xxx.xxx.231        1        0
xxx.xxx.xxx.232        1        0
xxx.xxx.xxx.233        1        0
xxx.xxx.xxx.234        1        0
xxx.xxx.xxx.235        1        0
xxx.xxx.xxx.236        1        0
xxx.xxx.xxx.237        1        0
xxx.xxx.xxx.238        1        0
xxx.xxx.xxx.239        1        0
xxx.xxx.xxx.240        1        0
xxx.xxx.xxx.241        1        0
xxx.xxx.xxx.242        1        0
xxx.xxx.xxx.243        1        0
xxx.xxx.xxx.244        1        0
xxx.xxx.xxx.245        1        0
xxx.xxx.xxx.246        1        0
xxx.xxx.xxx.247        1        0
xxx.xxx.xxx.248        1        0
xxx.xxx.xxx.249        1        0
xxx.xxx.xxx.250        1        0
xxx.xxx.xxx.251        1        0
xxx.xxx.xxx.252        1        0
xxx.xxx.xxx.253        1        0
xxx.xxx.xxx.254        0        2
xxx.xxx.xxx.255        1        0
xxx.xxx.xxx.256        4        0


IP's with result >= 1
xxx.xxx.xxx.1
xxx.xxx.xxx.7
xxx.xxx.xxx.16
xxx.xxx.xxx.24
xxx.xxx.xxx.26
xxx.xxx.xxx.27
xxx.xxx.xxx.28
xxx.xxx.xxx.29
xxx.xxx.xxx.31
xxx.xxx.xxx.32
xxx.xxx.xxx.34
xxx.xxx.xxx.35
xxx.xxx.xxx.38
xxx.xxx.xxx.39
xxx.xxx.xxx.40
xxx.xxx.xxx.47
xxx.xxx.xxx.53
xxx.xxx.xxx.54
xxx.xxx.xxx.56
xxx.xxx.xxx.62
xxx.xxx.xxx.63
xxx.xxx.xxx.97
xxx.xxx.xxx.100
xxx.xxx.xxx.103
xxx.xxx.xxx.220
xxx.xxx.xxx.254

So all IP's listed under "IP's with result >= 1" (except for 254) could be possible local PCs?

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

So all IP's listed under "IP's with result >= 1" (except for 254) could be possible local PCs?

That would depend on what the first three octets are, but assuming you are pinging a private address range, then yes.

Any of the following ranges would definitely be private/local LAN/WAN addresses:

10.0.0.0 - 10.255.255.255

127.16.0.0 - 172.31.255.255

192.168.0.0 - 192.168.255.255

169.254.0.0 - 169.254.255.255 (special case where a DHCP client cannot find a DHCP server)

These would refer to your local PC (not needing a network connection at all):

127.0.0.1 - 127.255.255.255

Pinging either of these two addresses could receive responses from just about anywhere, and are not useful for pinging:

0.0.0.0

255.255.255.255

There are some other special use IP addresses out there, but these are the main ones to worry about.

---Edit---

Keep in mind that @IPAddress1 gives you the first IP address assigned to your PC. It could be your local LAN, It could be an IP from wireless, from a broadband connection, or from a VPN connection. You might have both a private address and a public one. There is no way to know which one @IPAddress1 is returning. In my work, I commonly see PCs with one local LAN IP(private), one broadband IP(public), and one VPN IP(private).

Edited by willichan
Link to comment
Share on other sites

Ahh, ok.

I only used @IPAddress1.

I totally forgot that @IPAddress .1 to .256 isn't the only IP on the local network. ;)

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Even though your problem seems to have been solved, I would like to add that I also use _GetIP from INet Management UDF to check whether I'm connected or not or also if my IP changed -I have dynamic IP-

#include <Inet.au3>
$PublicIP = _GetIP()
While @error = 1
   $PublicIP = _GetIP()
WEnd
MsgBox(0, "IP Address", "Your IP Address is: " & $PublicIP)
Link to comment
Share on other sites

  • 1 year later...

Hi All,

I have had a similar problem, complied a program in XP and always works with he ping function. I am writing an connection application for a 3G module.

If connected the returns "0" for @error and a number greater the "0" for the return.

However the same program moved to Windows 7 - when I have disconnected my 3G connecton - it reports "0" for @error and "1" for the return of the ping. If I then connect it reports "0" for @error and a number greater the "0" for the return.

The problem is that I cannot use an IF statement of IF $var > "1" as when the connection is FAST I recieve 1ms ping response and the connection thinks it is disconnected.

very frustrating........

any help would be great.

;-------------------------  IF SIGNAL STRENGHT IS OK CONTINUE WITH DIAG
   If $Signal > 7 Then
    filewriteline($filelog,"Signal greater then 7% starting loop" & @CRLF)
    TraySetToolTip("Signal greater then 7% starting loop")
    ; Msgbox(0, "Debug","Starting ping in loop as signal strenght is greater then treshold value was : " & $asResult[0])
    ping($DecryptIP)
    ping($DecryptIP)
    ping($DecryptIP)
;-------------------------  Run Ping and log profiles
    CMDAndLog('netsh mbn show signal interface="Mobile Broadband Connection"', -1, True)
    RunWait(@ComSpec & " /c " & "ping " & $DecryptIP & " >>log.txt", @ScriptDir, @SW_HIDE)
    $rc = _RunDos("ping " & $DecryptIP & @ScriptDir & " >> " & $filelog & @CRLF)
    CMDAndLog('ping ' & $DecryptIP , -1, True)
    Sleep(2000)
    ;$DecryptIP = "203.124.94.23"
    $var = Ping($DecryptIP,2000)
;~   MsgBox(0,'@@ Debug  propoer ping', '$DecryptIP = ' & $var & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
;~   MsgBox (0, "google ping", Ping ("www.google.com.au"))
;~   MsgBox (0, "error of google",@error )
;~   MsgBox (0, "proper ping", Ping ($DecryptIP))
;~   MsgBox (0, "error of propper",@error)
;~   MsgBox (0, "", "Ping Online, roundtrip was: " & $var)
;~   MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$DecryptIP' & @lf & @lf & 'Return:' & @lf & $DecryptIP) ;### Debug MSGBOX
;~   MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & 'Ping($DecryptIP,2000)' & @lf & @lf & 'Return:' & @lf & Ping($DecryptIP,2000)) ;### Debug MSGBOX
;~   FileWriteLine($filelog,"Ping Online, roundtrip was: " & $var)
;-------------------------  IF PING FAILS CHECK CONNECTION STATUS
     ; Msgbox(0, "Debug","ping state loop will begin next")
     If $var > 1 Then
      TraySetToolTip("Ping is OK")
      ; Msgbox(0,"Status","Online, roundtrip was: " & $var & "  error  " & @error & "  count " & $i & @CRLF & " Ping is OK loop terminated and unit will now sleep") ; re-enstate this to check the time of the ping and check any errors of the system.
      $i = $i + 1
      FileWriteLine($filelog,"Connection is operating as normal sleeping for 2 minutes" & @CRLF & @CRLF)
     Else
      TraySetToolTip("Ping failed stratign remove seqence")
;-------------------------   IF CONNECTION IS FALSE AND THE CONNECTION MANAGER IS NOT IN A CORRECT STATE THEN PROCESS WILL BEGIN TO REBUILD CONNECTIOIN
      CMDAndLog('------------ Beginning of Reset cycle ! -----------------', -1, True)
      TraySetIcon(@ScriptDir & "\Signal_NOe.ico")
      TraySetToolTip("Rebuilding connection")
      TraySetState(4)
      Sleep (2000)
      Msgbox(0, "Debug Network Connect","removing profile")
      Remove()
      sleep (2000)
      Msgbox(0, "Debug Network Connect", "resetting device")
      ;RunWait(@ComSpec & " /c " & "device.bat disable >>log.txt", @ScriptDir, @SW_HIDE)
      CMDAndLog('device.bat disable', -1, True)
      sleep(4000)
      sleep (6000)
      ;$rc = _RunDos("net stop WwanSvc >> log.txt")
      CMDAndLog('net stop WwanSvc',-1,True)
      sleep (2000)
      ;$rc = _RunDos("net start WwanSvc >> log.txt")
      CMDAndLog('net start WwanSvc',-1,True)
      sleep(2000)
      ; Msgbox(0, "Debug Network Connect", "enabling device")
      ;RunWait(@ComSpec & " /c " & "device.bat enable >>log.txt", @ScriptDir, @SW_HIDE)
      CMDAndLog('device.bat enable',-1,True)
      sleep(4000)
      MsgBox (64, "user", " User name used is '" & $DecryptUserName & "'")
      if $DecryptUserName <> "" Then
       ;$rc = _RunDos("branding.cmd " & @ScriptDir & "\3gIcon.ico" & " -a " & $DecryptAPN & " -u " & $DecryptUserName & " -p " & $DecryptPassword & ">>log.txt")
       CMDAndLog("branding.cmd " & @ScriptDir & "\3gIcon.ico" & " -a " & $DecryptAPN & " -u " & $DecryptUserName & " -p " & $DecryptPassword & ">>log.txt",-1,True)
       Else
       ;$rc = _RunDos("branding.cmd " & @ScriptDir & "\3gIcon.ico" & " -a " & $DecryptAPN );& " -u " & $DecryptUserName & " -p " & $DecryptPassword & ">>log.txt")
       CMDAndLog("branding.cmd " & @ScriptDir & "\3gIcon.ico" & " -a " & $DecryptAPN,-1,True)
      EndIf
      $i = $i + 1
      $reset = $reset + 1
      ; Msgbox(0, "Debug Network Connect", "writing count to file")
      filewrite($filelog," Reset Count now at : " & $reset & @CRLF)
      EndIf
      EndIf
$Ping = Ping($DecryptIP,2000)
$error = @error
If $Ping Then
Select
   Case $Signal <= 7
   TraySetIcon(@ScriptDir & "\Signal_NO.ico")
   TraySetToolTip("3G Signal strenght Not available in this area")
   TraySetState(8) ; Show the tray icon
   Case $Signal > 7 AND $Signal <= 30
   TraySetIcon(@ScriptDir & "\Signal_low.ico")
   TraySetToolTip("Signal Strength low: - " & $signal & " %")
   TraySetState(8) ; Show the tray icon
   Case $Signal > 30 AND $Signal <= 70
   TraySetIcon(@ScriptDir & "\Signal_50.ico")
   TraySetToolTip("Signal Strength Medium: - " & $signal & " %")
   TraySetState(8) ; Show the tray icon
  Case $Signal > 80
   TraySetIcon(@ScriptDir & "\Signal_100.ico")
   TraySetToolTip("Signal Strength Excellent - " & $signal & " %")
   TraySetState(8) ; Show the tray icon
EndSelect
Else
TraySetIcon(@ScriptDir & "\Signal_NOe.ico")
TraySetToolTip("Connection not available in this area, system will re-try when Proper Signal is available.")
TraySetState(8)
EndIf
TraySetToolTip("sleeping before next cycle")
; Msgbox(0, "Debug Sleep", "Begin Sleep")
sleep (120000)
WEnd
fileclose($filelog)
Link to comment
Share on other sites

Posting to an old (over 1 year) post won't get you as many responses as you might hope. You should really create a new topic.

Did you look at all of the points mentioned in

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...