Thread: Ping via VBA
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Garry Douglas[_2_] Garry Douglas[_2_] is offline
external usenet poster
 
Posts: 4
Default Ping via VBA

Thanks.

I tried the following:

Str = "192.168." & c & "." & d
Open "TESTFILE" For Output As #1
Write #1, Shell("cmd /c ping " & Str & " C:\ping2.txt")
Close #1 ' Close file.

Stepping through the code, on the first iteration the routine pasted 2544 in
Testfile, second time round it was 7368.

I'm not sure what these numbers represent but whatever the values are they
do not appear to be appended to the file. I assume that this is because I am
closing and then re-opening the file on each pass.

I looked at Help but it doesn't :-)

Garry

"Smallweed" wrote in message
...
You've put the variables between the quotes so they're being read
literally.
Best to declare a string variable and concatenate:

strPing="cmd /c ping" & a & "." & b & "." etc
Shell (strPing)

Re appending to a text file, I'm a bit rusty on that but VBA help is OK -
try looking up "Write #"

"Garry Douglas" wrote:

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