Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pinging an IP Address 4

Status
Not open for further replies.

sheronne

Programmer
Jun 1, 2001
71
0
0
US
Is there anyway to PING an IP Address using foxpro?
 
mgagnon,

I have tried ! and RUN; however, I have no way of knowing if it returned true or not? Is there anyway to tell?

Thanks
 
sheronne

Doesn't it pop up a DOS window with the ping result? or do your need to trap the result?
 
Yeah, it pops up with a DOS window, but I need to trap the results to use later.
 
Here is a description of Rick Strahl's wwIpStuff library (sharewhare from that may work for you:

New wwIPStuff::HTTPPing method
This method allows quick checks of whether an Internet connection is available. Method lets you set a timeout and servername to hit and returns .t. or .f. depending of whether the server could be reached in time.
 
RUN ping 10.90.1.2 > c:\ping.txt && ping the server to file ping.txt

** RUN ping 10.1.1.8 > c:\ping.txt && local test ping

** create a cursor to capture the txt file
CREATE CURSOR temp (stuff c(80))
SELECT temp
APPEND FROM c:\ping.txt sdf && append txt file to cursor
GO BOTTOM && 2nd to last line contains fields of interest
SKIP -1
pingmin = INT(VAL(SUBSTR(stuff,AT('ms',temp.stuff,1)-3,3))) && 1st occur of 'ms'
pingmax = INT(VAL(SUBSTR(stuff,AT('ms',temp.stuff,2)-3,3))) && 2nd
pingave = INT(VAL(SUBSTR(stuff,AT('ms',temp.stuff,3)-3,3))) && 3rd

USE IN temp
DELETE FILE c:\ping.txt
RETURN pingmin, pingmax, pingave
 
you can test for the appearance of the ping.txt to see if the ping ran successfully, if you need to.
if file('ping.txt')
do stuff here
else
dont do stuff
endif
 
bigtroutz,

That worked perfectly, just what I needed.

Thanks
 
Bigtroutz,

Yet another question. That will work great, however, I would like to be able to NOT have the DOS window flash. I have read about optional parameters for the RUN command, but I can't seem to get them to work. Any suggestions?

 
Scratch the last question. I searched the forums for RUN command and found a link to some code that helped me.

Bigtroutz, thanks for your help. And,

Thanks to David W. Grewe for the code example that was posted!
 
I found bigtroutz code for pinging to text a solution for getting the user's ip address that I needed. (gave him a star already)

I also would like the command prompt window to NOT appear. I have searched but was not as lucky to find my answer.

Sherrone, what did you find? I would appreciate your help.

Thank you,
Jdemmer
 
Hi jdemmer..

Use the following command.. to avoid the DOS window..

RUN /N7 ping 10.90.1.2 > c:\ping.txt
Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Ramani

RUN /N7 ping 10.90.1.2 > c:\ping.txt

That deserves a star. I've been looking all day for that "7". I know I seen it somewhere
Mike Gagnon
 
Ramani,

Thanks, but while I don't see a window, the code does not execute.

I want to get the ip address of the user's computer to pass to Lexmark/Scopeware electronic document storage application.

Since I could not find an api call to do this, I implemented the above code from bigtroutz to save the results to a text file.

The code runs perfectly without the /N7 but does not create ping.txt with the /N7. I had tried the /N2 also, but it did not work either.

m.computername is obtained from api call GetComputerName

Code:
	private strIPCopy
	m.strIPCopy = ''

	m.strIPCopy = "run /N7 ping " + m.computername + ">c:\mas\temp\ping.txt"

	&strIPCopy

Thanks for your help, I really don't want the users to see the window, they may try to close it and then the print job would not work.

jdemmer
 
HI jdemmer,

You are right... but the work around is...

private strIPCopy
m.strIPCopy = ''
m.strIPCopy = "run /N7 ping " + m.computername ;
+ ">c:\mas\temp\ping.txt"
STRTOFILE(m.strIPCopy,"myPing.bat")
RUN /N7 myPing.Bat

Hope this helps you :) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Hi ramani,
Well, this didn't do it.

Files ping.txt and ping.bat are created. Ping.txt is what I ask it to be but ping.txt is empty.

I tried with /N7 and without. Still the same, ping.txt is empty.

Any thoughts?

Thanks for taking the time to look at this.

Jdemmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top