Current location - Trademark Inquiry Complete Network - Trademark inquiry - How to PING in Delphi, thank you, heroes.
How to PING in Delphi, thank you, heroes.
The simple way to realize the ping function in delphi is:

First, call windows ping directly? Command, and then get its output information.

Second, borrow Indy component package? TIdIcmpClient? Component (code from the Internet):

Program? TForm 1。 Button 1Click (sender:? to object);

defined variable

Me? :? Integer;

begin

Memo 1。 Clear lines.

IdIcmpClient 1。 Moderator: =? Edit 1。 Text; ? //The name or IP address of the computer

IdIcmpClient 1。 receive time out:= 1000; ? //Maximum timeout

Button 1. Enable? :=? Fake; ?

attempt

For what? Me: =0? Where to? 13? do

begin

IdIcmpClient 1。 Ping;

Apply. Processing messages? ; ? //delay

End;

finally

Button 1. Enable? :=? True; ?

End;

End;

Program? TForm 1。 Idcmpclient1reply (ASender:? TComponent

const? AReplyStatus:? TReplyStatus);

var?

sTime:? String;

Start?

//Detect Ping response error?

What if? (AReplyStatus。 MsRoundTripTime? =? 0? )? then what

sTime? :=? & lt 1'?

Or what?

sTime? :=? '='; ?

//Display the Ping message in the list box?

Memo 1。 Lines.Add (format ('reply? From where? [%s]? :? Bytes =%d Time %s%d? ms? TTL=%d ',

[AReplyStatus。 FromIpAddress,?

AReplyStatus。 Number of bytes received.

Time?

AReplyStatus。 MsRoundTripTime,?

AReplyStatus。 time tolive]));

End; Third, write the ping function and realize the function code.