unit ping;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls, winsock;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> ip: TEdit;<br> procedure Button1Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br> ip_option_information = record<br> ttl: char;<br> tos: char;<br> flags: char;<br> optionssize: char;<br> optionsdata: DWORD;<br> end;<br><br> icmp_echo_reply = record<br> address: u_long;<br> status: u_long;<br> roundtriphome: u_long;<br> datasize: integer;<br> reserved: integer;<br> datapointer: u_long;<br> options: ip_option_information;<br> data: array[0..250] of char;<br> end;<br><br>function IcmpCreateFile()
WORD; stdcall; external 'icmp.dll'; <br>function IcmpCloseHandle(IcmpHandle
WORD)
WORD; stdcall; external 'icmp.dll';<br>function IcmpSendEcho(IcmpHandle, DestinationAddress: DWORD; requestData:<br> string; requestSize: integer; requestOption: DWORD; var replyBuffer:<br> icmp_echo_reply; replySize, timeout: DWORD)
WORD; stdcall; external 'icmp.dll';<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br> NetAddress: u_long;<br> hFile,ret: dword;<br> msg: string;<br> preturn: icmp_echo_reply;<br>begin<br> NetAddress := inet_addr(pchar(ip.text));<br> hFile:=IcmpCreateFile() ;<br> IF hFile = 0 THEN exit;<br> msg := 'fdsfkj';<br> ret:=IcmpSendEcho(hFile,NetAddress,msg,Length(msg),0,preturn,282,200);<br> IcmpCloseHandle(hfile);<br> if ret > 0 then<br> showmessage('ok')<br> else<br> showmessage('fail');<br><br>end;<br><br>end.<br>