Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Pinging stuff
Message
 
À
28/10/2004 10:00:59
Carl Dobson
Reference Point Computers
Overbury, Tewks, Royaume Uni
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Versions des environnements
Visual FoxPro:
VFP 7
OS:
Windows XP
Divers
Thread ID:
00955268
Message ID:
00955359
Vues:
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 do not have VFP 7 to test, but I guess it should not be a problem, so, as long as the computer running the program has Windows XP or better you can use the Win32_PingStatus class, here you have a sample.
lparameters tcTarget, tlVerbose

local loWMI, loPingResults, loPingResult, lcTarget

if Vartype(tcTarget) # 'C'
	if tlVerbose
		wait window 'Invalid Target' timeout 10
	endif
	return .f.
endif

lcTarget	= Alltrim(tcTarget)
loWMI		= GetObject("winmgmts:")
loPingResults	= loWMI.ExecQuery("SELECT * FROM Win32_PingStatus WHERE Address = '" + lcTarget + "' and ResolveAddressNames=TRUE")

For Each loPingResult In loPingResults
	with loPingResult
		if tlVerbose
			If .StatusCode = 0
				If Lower(lcTarget) = .ProtocolAddress
					? lcTarget + " is responding"
				Else
					? lcTarget + "(" + .ProtocolAddress + ") is responding"
				EndIf
				? "Bytes = ", .BufferSize
				? "Time (ms) = ", .ResponseTime
				? "TTL (s) = ", .ResponseTimeToLive
				? "Resolve Address Names? = ", .ResolveAddressNames
			Else
				? lcTarget + " is not responding"
				? "Status code is ", .StatusCode
			endif
			? ''
		EndIf
		return Iif(Isnull(loPingResult.StatusCode), .f., loPingResult.StatusCode = 0)
	endwith
Next

return .f.
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?

"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare

"To die for a religion is easier than to live it absolutely"
Jorge L. Borges
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform