Link to home
Create AccountLog in
Avatar of John Sheehy
John SheehyFlag for United States of America

asked on

How do I ping a list of computers from a table

I have a table (tblHostNames) that has a list of all our PC names in it. These hostnames are displayed on a form.  I would like to have button that pings each host name and if it is reachable it changes the color to green and if not then to red.  I know I can use conditional formatting for the color changes so that's not an issue.  I just can't find much when it comes to using a table to ping host names.  Is there a way to do this?

Thanks
John

Avatar of Bembi
Bembi
Flag of Germany image

I hope you know what you are asking for...
As you have to go deeply inside the Windows API

But somebody has collected some code together...
https://blog.protocolsyntax.com/2014/01/17/followup-dns-lookup-and-ping-in-excel

A bit easier is this tool...
http://www.oette.info/
WOL2
rather a tool for Wake up on LAN, but you can scan your network and it collects all available machines together as well as you can add your owns and scans on the fly if they are online or not.
ASKER CERTIFIED SOLUTION
Avatar of Jim Dettman (EE MVE)
Jim Dettman (EE MVE)
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
That's all 32bit BTW and it has Ping() and DoPing().

Jim.
Avatar of John Sheehy

ASKER

I like it and I was able to modify it to 64Bit.  However, how do I get it to loop through the table tblHostName, and update the field fldStatus?

Thanks
John

Dim db as DAO.Database
Dim rs as DAO.Recordset
Dim bolRet as Boolean

Set db = CurrentDB()
Set rs = db.Openrecordset("tblHostName")

Do until rs.EOF
     bolRet = Ping(.......
      rs.Edit
      rs![fldStatus] = bolRet
      rs.Update
Loop

rs.close
set rs = nothing
set db = nothing
I get a Expected variable or procedure, not module compile error
it is highlighting Ping on the bolRet line

I entered this:
bolRet = Ping("Host_Name") Host_Name is the name of the field that contains the data.

Does it need to be
bolRet = Ping(rs![host_name])

Thanks
John

Nope that didn't work
John,

 The Ping() call is this:

Public Function Ping(Address As String, RoundTripTime As String, DataMatch As Boolean, Optional DataSize As Long = 32, Optional TimeOut As Long = PING_TIMEOUT)

At a minimum, you need to supply the address, and a variable for round trip time, and data match.  The last two are used to pass values back to you from the function.     Only data size and timeout are optional in the call.

 and yes, it would be rs![host_name]

 So:

 Dim strRoundTripTime as string
 Dim bolDataMatch as Boolean

 bolRet = Ping (rs![host_name], strRoundTripTime, bolDataMatch)

Jim.
Jim,

Appreciate the explanation.  However I am still getting the same error on the word Ping

So I have this as the button code:

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim bolRet As Boolean

DoCmd.Hourglass True

Set db = CurrentDb()
Set rs = db.OpenRecordset("tblHostName")

Do Until rs.EOF
      bolRet = Ping(rs![Host_Name], strRoundTripTime, bolDataMatch)
      rs.Edit
      rs![fldStatus] = bolRet
      rs.Update
Loop
DoCmd.Hourglass False

rs.Close
Set rs = Nothing
Set db = Nothing

Open in new window

Then everything else is in a module.

Jim,

So Figured out that error.  I had the module named Ping.  Changed the name and the error went away.  Now I have a new one.

Compile Error:
ByRef Argument type mismatch

It is highlighting strRoundTripTime

John

Make sure you add the dim statements:

Dim strRoundTripTime as string
 Dim bolDataMatch as Boolean

Since they are not dimmed, they end up as a variant, which is the wrong data type.

and you should be using Option Explicit in every module.   You'd catch an error like that when you went to compile.

Jim.
Jim,

That worked.....sort of.  
I have two records in the table for testing right now,  But it keeps looping on the first record.  So I tried it with the real data with over 1200 records and it is doing the same thing.  Only loops on the first record.

John

my apologies, I forgot:

      rs.Update
     rs.Movenext
Loop

DoCmd.Hourglass False
I guess Jim made a good job, the code is similar to the code behind my link.
There are some additional functions in the link...

Beside this, have a look on the WOL2 tool as it collects all devices together (which are online) and stores their IP, MAC and Name in an XML file which can be used to see all the time the online status.
You can also manually add devices if you know the MAC.
The basic purpose of the Tool was Wake up on  Lan, but I usually use it th check my infrastructure. 


Bembi,

That is the issue I have.  IT is telling me everything is online but when I run the Ping test it comes back with about 200 that are unreachable.  I report those to IT and they tell me it's because the system isn't connected.  Which to me means offline.

I will check out the WOL2 tool this morning.

Thanks
John


Sounds more like a routing or switch issue...
Possibly the ionformation of the IT is correct, the systems are online, but if a router or switch doesn't work as expected, you just can not reach them.
You may try to trace the path...
tracert IP
to see, if there is a routing path to the target.