Ping a list of computer names

M

mikeODBCISSUE

I am trying to ping a list of computer names in a table and put the ping
results into another table.

Any help would be greatly appreciated.

Mike
 
A

Al Camp

What do you mean by "Ping".
If you mean to find certain records in a table that meet a certain criteria, and create a
new table from those... then use a MakeTable query.
 
D

Danny J. Lesandrini

I don't know, but is it possible to pipe the results of the ping to a file?
If so, what is the dos command?
 
X

xRoachx

LOL! Ping is a command line command....Are you trying to test connectivity
or trying to check in the computer is online?

But I'm not sure if this can be done through VBA. I'd like to know the
answer to this one as well.
 
D

Danny J. Lesandrini

Actually, a quick google search revealed this syntax ...

ping BRGLS33 >>PingResults.log

Here's the results:

Pinging brgls14.rgl.net [192.168.0.14] with 32 bytes of data:

Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Now, the problem is how to execute a dos command from Access.
Can you perform a simple Shell command?

Shell "ping YourServer >>YourFile.txt"

If so, then you simply import the file data into Access, or open it
and step through each line, extracting the data. Not trivial, but
doable.
 
M

mikeODBCISSUE

Al

Ping means to ping the computer to see if its resides on the network.

Mike
 
D

Danny J. Lesandrini

Here's the VBScript to do it. Now it only needs to be converted to VBA

dim wsShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHshell.Run "%comspec% /c ping brgls14 >>C:\S14.log"

--
Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
Actually, a quick google search revealed this syntax ...

ping BRGLS33 >>PingResults.log

Here's the results:

Pinging brgls14.rgl.net [192.168.0.14] with 32 bytes of data:

Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Now, the problem is how to execute a dos command from Access.
Can you perform a simple Shell command?

Shell "ping YourServer >>YourFile.txt"

If so, then you simply import the file data into Access, or open it
and step through each line, extracting the data. Not trivial, but
doable.
--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
I don't know, but is it possible to pipe the results of the ping to a file?
If so, what is the dos command?
 
D

Douglas J. Steele

Randy Birch has code at
http://vbnet.mvps.org/code/internet/pingbyhostname.htm to use APIs, rather
than resorting to shelling to Shell.

Obligatory warning: Randy's site is aimed at VB programmers. Since there are
significant differences between the controls available for forms in VB and
Access, some of his examples don't port directly to Access. This is one such
example: he's using a control array, which Access doesn't support.

For the record, the equivalent of that VBScript in VBA would like be:

Dim strShell As String

strShell = Chr$(34) & Environ$("comspec") & " /c " & _
"ping brgls14 >> C:\S14.log" & Chr$(34)
Shell strShell, vbHide

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Danny J. Lesandrini said:
Here's the VBScript to do it. Now it only needs to be converted to VBA

dim wsShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHshell.Run "%comspec% /c ping brgls14 >>C:\S14.log"

--
Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
Actually, a quick google search revealed this syntax ...

ping BRGLS33 >>PingResults.log

Here's the results:

Pinging brgls14.rgl.net [192.168.0.14] with 32 bytes of data:

Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Now, the problem is how to execute a dos command from Access.
Can you perform a simple Shell command?

Shell "ping YourServer >>YourFile.txt"

If so, then you simply import the file data into Access, or open it
and step through each line, extracting the data. Not trivial, but
doable.
--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
I don't know, but is it possible to pipe the results of the ping to a
file?
If so, what is the dos command?
 
X

xRoachx

Al -- I was beginning to wonder b/c I've read your posts before and I figured
you'd know that... :)
 
M

mikeODBCISSUE

Danny,

Thanks for you help. I tied the code below and received and "Object
Required" error message on the second line. Any suggestions.

Mike

Danny J. Lesandrini said:
Here's the VBScript to do it. Now it only needs to be converted to VBA

dim wsShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHshell.Run "%comspec% /c ping brgls14 >>C:\S14.log"

--
Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
Actually, a quick google search revealed this syntax ...

ping BRGLS33 >>PingResults.log

Here's the results:

Pinging brgls14.rgl.net [192.168.0.14] with 32 bytes of data:

Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Now, the problem is how to execute a dos command from Access.
Can you perform a simple Shell command?

Shell "ping YourServer >>YourFile.txt"

If so, then you simply import the file data into Access, or open it
and step through each line, extracting the data. Not trivial, but
doable.
--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
I don't know, but is it possible to pipe the results of the ping to a file?
If so, what is the dos command?
 
A

Al Camp

I misread the post. I thought Mike was trying to "ping" a table.
I missed the ball on that one...
Al Camp
 
M

mikeODBCISSUE

Doug,

Thanks for you assistance. I did try the code you suggested below but when I
ran it Access had a problem with the third line (Invalid procedure call or
argument). I went and commented out this line and ran the code again. Nothing
happened and the "S14.log" never showed up on the C drive. Any further
suggestions.

MIke

Douglas J. Steele said:
Randy Birch has code at
http://vbnet.mvps.org/code/internet/pingbyhostname.htm to use APIs, rather
than resorting to shelling to Shell.

Obligatory warning: Randy's site is aimed at VB programmers. Since there are
significant differences between the controls available for forms in VB and
Access, some of his examples don't port directly to Access. This is one such
example: he's using a control array, which Access doesn't support.

For the record, the equivalent of that VBScript in VBA would like be:

Dim strShell As String

strShell = Chr$(34) & Environ$("comspec") & " /c " & _
"ping brgls14 >> C:\S14.log" & Chr$(34)
Shell strShell, vbHide

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Danny J. Lesandrini said:
Here's the VBScript to do it. Now it only needs to be converted to VBA

dim wsShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHshell.Run "%comspec% /c ping brgls14 >>C:\S14.log"

--
Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
Actually, a quick google search revealed this syntax ...

ping BRGLS33 >>PingResults.log

Here's the results:

Pinging brgls14.rgl.net [192.168.0.14] with 32 bytes of data:

Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Now, the problem is how to execute a dos command from Access.
Can you perform a simple Shell command?

Shell "ping YourServer >>YourFile.txt"

If so, then you simply import the file data into Access, or open it
and step through each line, extracting the data. Not trivial, but
doable.
--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


I don't know, but is it possible to pipe the results of the ping to a
file?
If so, what is the dos command?
 
D

Danny J. Lesandrini

This isn't perfect, by any means, but here it is.


Public Function FooShell()
Dim WSHshell

Set WSHshell = CreateObject("WScript.Shell")
WSHshell.Run "%comspec% /c ping brgls14 >>C:\S14.txt"

' need to pause here for file to be created before running
' the TransferText call.
DoCmd.TransferText acImportDelim, , "import_s14", "C:\S14.txt", False
End Function



--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


mikeODBCISSUE said:
Danny,

Thanks for you help. I tied the code below and received and "Object
Required" error message on the second line. Any suggestions.

Mike

Danny J. Lesandrini said:
Here's the VBScript to do it. Now it only needs to be converted to VBA

dim wsShell
Set WshShell = WScript.CreateObject("WScript.Shell")
WSHshell.Run "%comspec% /c ping brgls14 >>C:\S14.log"

--
Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


Danny J. Lesandrini said:
Actually, a quick google search revealed this syntax ...

ping BRGLS33 >>PingResults.log

Here's the results:

Pinging brgls14.rgl.net [192.168.0.14] with 32 bytes of data:

Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

Now, the problem is how to execute a dos command from Access.
Can you perform a simple Shell command?

Shell "ping YourServer >>YourFile.txt"

If so, then you simply import the file data into Access, or open it
and step through each line, extracting the data. Not trivial, but
doable.
--

Danny J. Lesandrini
(e-mail address removed)
http://amazecreations.com/datafast


I don't know, but is it possible to pipe the results of the ping to a file?
If so, what is the dos command?
 
D

Danny J. Lesandrini

Ooops, that one got away before I was finished.

The code I had posted worked in a .VBS file, but needed a couple of
little teaaks to run from a VBA module. What's below worked for me when
I tested it.

The TransferText command requires that the file have a .txt extension,
not a .log extension, so I edited that as well. Also, I made a note about
how there needs to be a pause before executing TransferText, so that the
file is actually there. Not sure how you will get around this, but there are
pause functions out there, and since there's a ShellWait, maybe there is
an equivilent for the WSHShell object.
 
M

mikeODBCISSUE

Danny,

Thanks for you help. I was able to find a "wait" funciton on the MS
knowledge base website see below. All I need to do now is to find an easy way
to evaluate the results of the ping to see if it was good or not. If you have
any suggestions please pass them my way.

Public Function Wait(Delay As Integer, DispHrglass As Integer)

Dim DelayEnd As Double
DoCmd.Hourglass DispHrglass
'(In Microsoft Access 2.0 and 1.x use: DoCmd Hourglass DispHrglass)
DelayEnd = DateAdd("s", Delay, Now)
While DateDiff("s", Now, DelayEnd) > 0
Wend
DoCmd.Hourglass False
'(In Microsoft Access 2.0 and 1.x use: DoCmd Hourglass False)

End Function

Thanks again.

Mike
 
D

Danny J. Lesandrini

Mike:

I do have an idea, but I don't know if it's good. The text file looks like
the results below, and when imported using TransferText, it includes
all the blank lines. After importing the data, I would run these scripts:
(Assuming the import table is named tblPingResults)

' Get rid of the empty rows
CurrentDb.Execute "DELETE FROM tblPingResults Where Nz([Field1],'')=''"

' Now count the things you want.

If DCount("*","tblPingResults ", "[Field1] LIKE 'ReplyFrom*'") = 4 Then
' Success
End If

Now it's just a matter of peeking into the table to see the results. I'm not
familiar enough with Ping to know what to look for, but you would use
calls like the ones above ... or something more sophisticated :)



Pinging brgls14.rgl.net [192.168.0.14] with 32 bytes of data:

Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128
Reply from 192.168.0.14: bytes=32 time<1ms TTL=128

Ping statistics for 192.168.0.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top