Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pinging stuff
Message
From
29/10/2004 14:28:03
 
 
To
28/10/2004 10:00:59
Carl Dobson
Reference Point Computers
Overbury, Tewks, United Kingdom
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 7
OS:
Windows XP
Miscellaneous
Thread ID:
00955268
Message ID:
00955903
Views:
22
>How do I ping a web address or ipaddresses ?all I need is a return value of .T. or .F. which would then automatically populate the check boxes.

I did not write this, but it work good. Copy the code to Ping.PRG
* by josh@jassing.com
* with LOTS of help from (actually; all the hard work by) Markus Voellmy
*
* ?ping("jassing.com",80) would check jassing.com to be sure it's running a web server
* NOTE: it does not do any dns lookups; so if you're checking for a mail server, you need
* 	to resolve the mx record yourself.
#DEFINE sckClosed				0
#DEFINE sckOpen					1
#DEFINE sckListening			2
#DEFINE sckConnectionPending 	3
#DEFINE sckResolvingHost 		4
#DEFINE sckHostResolved 		5
#DEFINE sckConnecting 			6
#DEFINE sckConnected 			7
#DEFINE sckClosing 				8
#DEFINE sckError 				9


LPARAM tcServer
LOCAL lnState, loPing, lnLast
tnPort = 80
*!*	DECLARE INTEGER OutputDebugString ;
*!*		IN kernel32 ;
*!*		AS dbgout;
*!*		STRING cString
LOCAL llResult
llResult = .t.
loPing=CREATEOBJECT("mswinsock.winsock")
WITH loPing
	.remoteport = tnPort
	.remotehost = tcServer
	.CONNECT()
	lnLast = -1
	DO WHILE .state < sckConnected
		IF lnLast # .state
*			dbgout( "Ping State: "+PingState( .state ))
*? "Ping State: "+PingState( .state )
			lnLast = .state
		ENDIF
	ENDDO
*	dbgout( "Ping State: "+PingState( .state ))
*? "Ping State: "+PingState( .state )
	lnState = .state
	.CLOSE()
*	dbgout("Ping State: "+PingState(.state))
*? "Ping State: "+PingState( .state )
ENDWITH
RETURN lnState#9


FUNC PingState
	LPARAM tnState
	LOCAL lcState
	DO CASE
		CASE tnState = sckClosed
			lcState = "Closed"
		CASE tnState = sckOpen
			lcState = "Open"
		CASE tnState = sckListening
			lcState = "Listening"
		CASE tnState = sckConnectionPending
			lcState = "Waiting"
		CASE tnState = sckResolvingHost
			lcState = "Resolving"
		CASE tnState = sckConnecting
			lcState = "Connecting"
		CASE tnState = sckConnected
			lcState = "Connected"
		CASE tnState = sckClosing
			lcState = "Closing"
		CASE tnState = sckError
			lcState = "Error"
		OTHERWISE
			lcState = "Unknown"
	ENDCASE
	RETURN lcState
Greg Reichert
Previous
Reply
Map
View

Click here to load this message in the networking platform