Thread: Ping via VBA
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Ping via VBA

This may help

Dim a As Long, b As Long, c As String
Dim y As Long, z As Long
For y = 0 To 255
For z = 0 To 255
Let a = 192
Let b = 0
c = a & "." & b & "." & y & "." & z
Shell ("cmd /c ping " & c & " c:\ping.txt")
Next z
Next y


--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Garry Douglas" wrote in message
...
Hi

Is it possible to ping a range of local IP addresses in VBA code by
looping through the range using variables to produce a text file which
includes the results?

The range I want to ping is 192.168.0.0 to 192.168.255.255

I can create the nested loop command structure to increment the variables
but can't pass them to the ping command.

Extract of the code:

Option Explicit
Dim a,b,c,d,y,z
For y = 0 To 255
For z = 0 To 255
Let a = 192
Let b = 0
Let c = y
Let d = z
Shell ("cmd /c ping a.b.c.d c:\ping.txt")
Next z
Next y

This results in the following message being pasted to ping.txt:

"Ping request could not find host a.b.c.d. Please check the name and try
again" from which I assume the contents of the variables are not being
passed into the shell command.

Assuming the variables can be passed to the ping command, is it then
possible to append the results of each loop to the text file instead of
over writing it's contents?

The reason I want to do this is that I have a printer with a NIC that I
want to connect to my router and I think the printer has a fixed IP
address but I can't communicate with it and don't want to spend eternity
manually pinging all the addresses in the range until I hit the right one!
Unfortunately I don't have the manual for the NIC and the Kyocera website
isn't much help (not even sure the NIC card is a Kyocera).

Any suggestions appreciated.

Thanks

Garry Douglas