用个ICMP控件直接在程序里ping吧
不用控件也简单. 用api一样
uses winsock;
p_ip_options=^t_ip_options;
t_ip_options=packed record
Ttl: byte;
Tos: byte;
flags: byte;
optionssize: byte;
optionsdata: pointer;
end;
p_icmp_echo_reply=^t_icmp_echo_reply;
t_icmp_echo_reply=packed record
address: u_long;
status: u_long;
rttime: u_long;
datasize: word;
reserved: word;
data: pointer;
ip_options:t_ip_options;
end;
function icmpcreatefile: THandle; stdcall; external 'icmp.dll' name 'ICMPCreateFile';
function ICMPSendEcho:function(ICMPHandle: THandle;
DestAddress:longint;
Requestdata
ointer;
requestsize:word;
RequestOptns: p_ip_options;
ReplyBuffer
ointer;
Replysize:dword;
Timeout: DWord
):dword; stdcall; external 'icmp.dll' name 'ICMPSendEcho';
function ICMPCloseHandle:function(ICMPHandle:THandle):Boolean; stdcall; external 'icmp.dll' name 'ICMPCloseHandle';
function Ping(Ip: string): boolean;
var
f_ICMP_Handle: THandle;
f_address: LongInt;
f_timeout: Integer;
f_blocksize: Integer;
f_replysize: Integer;
requestoptions: T_ip_options;
reqyestdatam replybuffer: Pointer;
begin
f_ICMP_Handle:=icmpcreatefile;
f_timeout:=1000;
f_blocksize:=64;
f_replysize:=16+sizeof(t_icmp_echo_reply)+f_blocksize;
GetMem(requestdata,f_blocksize);
fillchar(requestdata^,64,#$32);
GetMem(replybuffer,f_replysize);
requestoptions.ttl:=255;
requestoptions.tos:=0;
requestoptions.flags:=0;
requestoptions.optionssize:=0;
requestoptions.optionsdata:=NIL;
f_address := Inet_Addr(PChar(Ip));
if f_address = SOCKET_ERROR then
begin
result := false;
ICMPCloseHandle(f_icmp_handle);
exit;
end;
if ICMPSendEcho(f_icmp_handle,f_address,
requestdata,f_blocksize,
@requestoptions,
replybuffer,f_replysize,
f_timeout)<>1 then
result := false
else
result := true;
icmpclosehandle(f_icmp_handle);
end;