Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Solution for pinging
Message
De
27/04/2006 11:39:45
 
 
À
27/04/2006 10:21:05
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Versions des environnements
Visual FoxPro:
VFP 9 SP1
Divers
Thread ID:
01117064
Message ID:
01117139
Vues:
19
Nice code!!
Thank you.


>If you are using Windows XP you can use the WMI WIN32_Ping class: otherwise you could pipe the output of the PING command into a textfile and parse it manually.
>
>
>local oWMI, cAddress, oPings, oPing, oItem
>
>oWMI = getobject("winmgmts:")
>* Specify address or computer name or URL
>cAddress = "10.128.25.14"
>* cAddress = "www.netscape.com"
>* cAddress = "computer_name
>
>if os() < "Windows 5.01" or os() = "Windows NT 4.00"
>	messagebox("This will only work in Windows XP/Server 2003")
>	return
>endif
>
>oPings = oWMI.ExecQuery([Select * from WIN32_Pingstatus where address='] + cAddress + ['])
>
>for each oPing in oPings
>	* This class does not actually support enumeration as such
>	* there is only one ping object returned and this is how we access it.
>
>	? "Status code: ", GetStatusCode(oPing.statuscode)
>	?
>	? "Address: ", oPing.Address
>	? "Buffer size", oPing.BufferSize
>	? "No Fragmentation", oPing.NoFragmentation
>	? "PrimaryAddressResolutionStatus", oPing.PrimaryAddressResolutionStatus
>	? "ProtocolAddress", oPing.ProtocolAddress
>	? "ProtocolAddressResolved", oPing.ProtocolAddressResolved
>	? "RecordRoute", oPing.RecordRoute
>	? "ReplyInconsistency", oPing.ReplyInconsistency
>	? "ReplySize", oPing.ReplySize
>	? "ResolveAddressNames", oPing.ResolveAddressNames
>	? "ResponseTime", oPing.ResponseTime
>	? "ResponseTimeToLive", oPing.ResponseTimeToLive
>	? "SourceRoute", oPing.SourceRoute
>	? "SourceRouteType", GetSourceRouteType(oPing.SourceRouteType)
>	? "Timeout", oPing.timeout
>	? "TimestampRoute", oPing.TimestampRoute
>	? "TimeToLive", oPing.TimeToLive
>	? "TypeofService", GetTypeOfService(oPing.TypeofService)
>
>	if not isnull(oPing.RouteRecord)
>		for each oItem in oPing.RouteRecord
>			? oItem
>		next
>	endif
>
>	if not isnull(oPing.RouteRecordResolved)
>		for each oItem in oPing.RouteRecordResolved
>			? oItem
>		next
>	endif
>
>	if not isnull(oPing.RouteRecordResolved)
>		for each oItem in oPing.TimeStampRecord
>			? oItem
>		next
>	endif
>
>	if not isnull(oPing.TimeStampRecordAddress)
>		for each oItem in oPing.TimeStampRecordAddress
>			? oItem
>		next
>	endif
>
>	if not isnull(oPing.TimeStampRecordAddressResolved)
>		for each oItem in oPing.TimeStampRecordAddressResolved
>			? oItem
>		next
>	endif
>
>next
>
>procedure GetSourceRouteType
>	lparameters nSourceRouteType
>
>	local cType
>
>	do case
>		case nSourceRouteType = 1
>			cType = "Loose Source Routing"
>		case nSourceRouteType = 2
>			cType = "Strict Source Routing"
>		otherwise
>			* Default - 0 - or any other value.
>			cType = "None"
>	endcase
>
>	return cType
>
>endproc
>
>procedure GetTypeOfService
>	lparameters nServiceType
>
>	local cType as string
>
>	do case
>		case nServiceType = 2
>			cType = "Minimize Monetary Cost"
>		case nServiceType = 4
>			cType = "Maximize Reliability"
>		case nServiceType = 8
>			cType = "Maximize Throughput"
>		case nServiceType = 16
>			cType = "Minimize Delay"
>
>		otherwise
>			* Default - 0 - or any other value.
>			cType = "Normal"
>
>	endcase
>
>	return cType
>
>endproc
>
>procedure GetStatusCode (cCode as string) as string
>
>	local cStatus
>
>	do case
>		case cCode = 0
>			cStatus = "Success"
>		case cCode = 11001
>			cStatus = "Buffer Too Small"
>		case cCode = 11002
>			cStatus = "Destination Net Unreachable"
>		case cCode = 11003
>			cStatus = "Destination Host Unreachable"
>		case cCode = 11004
>			cStatus = "Destination Protocol Unreachable"
>		case cCode = 11005
>			cStatus = "Destination Port Unreachable"
>		case cCode = 11006
>			cStatus = "No Resources"
>		case cCode = 11007
>			cStatus = "Bad Option"
>		case cCode = 11008
>			cStatus = "Hardware Error"
>		case cCode = 11009
>			cStatus = "Packet Too Big"
>		case cCode = 11010
>			cStatus = "Request Timed Out"
>		case cCode = 11011
>			cStatus = "Bad Request"
>		case cCode = 11012
>			cStatus = "Bad Route"
>		case cCode = 11013
>			cStatus = "TimeToLive Expired Transit"
>		case cCode = 11014
>			cStatus = "TimeToLive Expired Reassembly"
>		case cCode = 11015
>			cStatus = "Parameter Problem"
>		case cCode = 11016
>			cStatus = "Source Quench"
>		case cCode = 11017
>			cStatus = "Option Too Big"
>		case cCode = 11018
>			cStatus = "Bad Destination"
>		case cCode = 11032
>			cStatus = "Negotiating IPSEC"
>		case cCode = 11050
>			cStatus = "General Failure"
>
>		otherwise
>			cStatus = "Unknown"
>	endcase
>
>	return cStatus
>
>endproc
>
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform