Sign in to follow this  
Followers 0
datkewlguy

ping ip, check internet...is there a way

17 posts in this topic

#1 ·  Posted (edited)

OKAY i need a quick way to check if u have interent or not... i seemed to have forgotten how to do this...

ok well maybe not have internet, what i mean is if u are currently connected

Edited by datkewlguy

Share this post


Link to post
Share on other sites



OKAY i need a quick way to check if u have interent or not... i seemed to have forgotten how to do this...

ok well maybe not have internet, what i mean is if u are currently connected

<{POST_SNAPBACK}>

#include <file.au3>
$ip = 127.0.0.1
$sec = 1000
RunWait(@ComSpec & " /c " & 'ping ' & $ip & ' > ping.txt', "", @SW_HIDE)
Sleep($sec*5)
$file = FileOpen(@windir & "\ping.txt",0)

Ok, I just brainfarted, I'll finish the code later, but basically look to see if the IP returned a ping, if all the packets timed out, chances are you don't have internet.

by the way 127.0.0.1 is local loopback and will always return something, connected or not, so you may want to use microsoft.com or some other large buisness site as a test IP.


Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Share this post


Link to post
Share on other sites

I definitely need something like this.

I hope you can make it work, Larry.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is what ive been doing to check if networked computers are online

PingChk ()

Func PingChk ()
  RunWait(@ComSpec & " /c " & 'ping www.google.com -n 1 >> C:\Temp.txt', "", @SW_HIDE)

  $file = FileRead("C:\Temp.txt", FileGetSize("C:\Temp.txt"))

  If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
  Else 
        $find = StringInStr( $file, "Ping request could not find host www.google.ie") 
      
     If $find = 0 Then
           Msgbox(0,"Test", "Online")
     Else
           Msgbox(0,"Test", "Offline")
     EndIf
  EndIf
  FileDelete("C:\Temp.txt")
EndFunc

Edit: The above code will always work...... If you are under the assumption that www.google.com will never collect any down time :lmao:

@Lar But if you have a dllcall that would save all the above hassel...... im all ears o:)

Edited by Nova

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

This is what ive been doing to check if networked computers are online

<snip>

Edit: The above code will always work......

<{POST_SNAPBACK}>

Never say that.

It won't work in these cases:

* You are connected to the web through a proxy

* You don't use an English version of Windows

The following code is not universal.

;This returns false information; When I'm offline it returns "Online"
If Ping('127.0.0.1') Then
   MsgBox(64, "Test", "Online!")
Else
   MsgBox(64, "Test", "Offline!")
EndIf

;This returns the right information.
If Ping('www.google.com') Then
   MsgBox(64, "Test", "Online!")
Else
   MsgBox(64, "Test", "Offline!")
EndIf

One thing you could do (which I used in a script), is launch Internet Explorer and wait like 5 to 10 seconds.

And do WinExists('Part of website title like Google'). If it returns 0, you have no connection.

Edited by SlimShady

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I made an alternative.

If Online() Then
   MsgBox(64, "Test", "Online!")
Else
   MsgBox(64, "Test", "Offline!")
EndIf

Func Online()
   Local $IE_PID, $Online
   $IE_PID = Run('"' & @ProgramFilesDir & '\Internet Explorer\IEXPLORE.EXE" http://www.google.com', "", @SW_MINIMIZE)
   $Online = WinWait("Google - ", "", 5)
   ProcessClose($IE_PID)
   Return $Online
EndFunc
Edited by SlimShady

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Equals lar, equals:

$INTERNET_CONNECTION_LAN = 0x2

EDIT: Does this require a bitand() for returns, or subtraction, or what?

Edited by this-is-me

Who else would I be?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

[..]

EDIT: Does this require a bitand() for returns, or subtraction, or what?

<{POST_SNAPBACK}>

Yep .. like this ...

;--------------------------------------------------------------------------------------------
;check $ret[0] for trueness, and $ret[1] for type of connection according to variables provided...
;--------------------------------------------------------------------------------------------
$INTERNET_CONNECTION_MODEM        = 0x1
$INTERNET_CONNECTION_LAN            = 0x2
$INTERNET_CONNECTION_PROXY        = 0x4
$INTERNET_CONNECTION_MODEM_BUSY  = 0x8
$INTERNET_RAS_INSTALLED          = 0x10
$INTERNET_CONNECTION_OFFLINE        = 0x20
$INTERNET_CONNECTION_CONFIGURED  = 0x40

    $ret = DllCall("WinInet.dll","int","InternetGetConnectedState","int_ptr",0,"int",0)

    If $ret[0] then
       ;check type of connection
        $sX = ""
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM)    Then $sX = $sX & "MODEM" & @LF 
        If BitAND($ret[1], $INTERNET_CONNECTION_LAN)        Then $sX = $sX & "LAN" & @LF 
        If BitAND($ret[1], $INTERNET_CONNECTION_PROXY)    Then $sX = $sX & "PROXY" & @LF 
        If BitAND($ret[1], $INTERNET_CONNECTION_MODEM_BUSY) Then $sX = $sX & "MODEM_BUSY" & @LF 
        If BitAND($ret[1], $INTERNET_RAS_INSTALLED)      Then $sX = $sX & "RAS_INSTALLED" & @LF 
        If BitAND($ret[1], $INTERNET_CONNECTION_OFFLINE)    Then $sX = $sX & "OFFLINE" & @LF 
        If BitAND($ret[1], $INTERNET_CONNECTION_CONFIGURED) Then $sX = $sX & "CONFIGURED" & @LF 
    Else
        $sX = "Not Connected"
    Endif

    MsgBox(4096,$ret[0] & ":" & $ret[1],$sX)

Thanks Larry - very cool :lmao:

Edit: minor code improvement

Edited by trids

Share this post


Link to post
Share on other sites

Thanx trids and larry, this will both come in handy in a lot of cases.


Who else would I be?

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

First of to quote my self

The above code will always work...... If you are under the assumption that www.google.com will never collect any down time 

It was just a bad joke, im well aware that their are numerous things that could affect the out come of my posted script.

It works in the majority of cases :lmao:

Edit: Is there a dllcall I can use to check if a networked computer is on ?

Not that it has an internet connection but thats its on the network.

Example I currently ping the computers name and read the output.

But this can be quite slow.

Edited by Nova

Share this post


Link to post
Share on other sites

What I would like to be able to do I constantly check if a computer on my network is on and update an icon with results.

So check if its on, if it is display a green computer icon, if its off display a red icon.

At the moment using ping it takes about 3 seconds to ping, save and read the output in order to figure out the status of a computer.

If I had a nice fast dllcall that could do the same in under a second or so ,then I could constantly update the icons on my gui with the status of my networked computers.

Right now because I have 3 computers to check the status off on my home network I have put a refresh button on my gui which uses the ping method with each computer, so it takes 9 seconds to refresh the icons.

That just wont do :lmao:

So Lar or anyone one else who has mastered dll's any ideas ???

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

What I would like to be able to do I constantly check if a computer on my network is on and update an icon with results.

So check if its on, if it is display a green computer icon, if its off display a red icon.

At the moment using ping it takes about 3 seconds to ping, save and read the output in order to figure out the status of a computer.

If I had a nice fast dllcall that could do the same in under a second or so ,then I could constantly update the icons on my gui with the status of my networked computers.

Right now because I have 3 computers to check the status off on my home network I have put a refresh button on my gui which uses the ping method with each computer, so it takes 9 seconds to refresh the icons.

That just wont do  :lmao:

So Lar or anyone one else who has mastered dll's any ideas ???

<{POST_SNAPBACK}>

Use the Ping function found in the latest beta.

Here's what I use.

If Ping("127.0.0.1") Then
    MsgBox(0, "", "Computer is online!")
Else
    MsgBox(0, "", "Computer is offline!")
EndIf
Edited by SlimShady

Share this post


Link to post
Share on other sites

Tnx Slim, but that take the same amount of time as my current method if not longer.

Its speed im after.

Im trying to update an status icon in as close to real time as I can.

I was hoping there was a neat dllcall that could achieve such speed.

Share this post


Link to post
Share on other sites

Tnx Slim, but that take the same amount of time as my current method if not longer.

Its speed im after.

Im trying to update an status icon in as close to real time as I can.

I was hoping there was a neat dllcall that could achieve such speed.

<{POST_SNAPBACK}>

Do you think there is a faster way than "ping"?

Share this post


Link to post
Share on other sites

Do you think there is a faster way than "ping"?

I hope so :lmao:

For instances programs like Msn Messenger update there icons almost instantly.

I have over 40 contacts in my msn messenger list and as soon as a person either logs off or signs in there icon is instantly updated.

Im pinging 3 computer on my network and its taking 8 seconds.

There has to be a different way.

By the way im sure msn messenger uses a completly different method of finding clients and it probly cant be applyed to my problem, but there must be a faster method that the one im currently using.

Share this post


Link to post
Share on other sites

Is 3 seconds short enough?

$Start = @SEC
for $i = 1 To 3
   Ping("128.0.0.1", 750)
Next
MsgBox(64, "Test", "Started: " & $Start & @CRLF & "Finished: " & @SEC)

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