uses
Windows, SysUtils, Variants, Classes, Graphics, Controls,
ExtCtrls, ComCtrls, winsock, StdCtrls, wininet;
function Ping(
IP:
string; TimeOut:Cardinal):Boolean;
var hICMP : DWORD;
pierWork : PICMP_ECHO_REPLY;
dwSize : DWORD;
Class1,Class2,Class3,Class4 :
String;
i,j : Byte;
begin
Result:=False;
j:=1;
for i:=1
to Length(
IP)
do begin
if IP[i]<>'
.'
then begin
case j
of
1: Class1:=Class1+
IP[i];
2: Class2:=Class2+
IP[i];
3: Class3:=Class3+
IP[i];
4: Class4:=Class4+
IP[i];
end;
end else
Inc(j);
end;
hICMP := IcmpCreateFile;
if hICMP = INVALID_HANDLE_VALUE
then exit;
try
dwSize := SizeOf(ICMP_ECHO_REPLY)+8;
pierWork := AllocMem(dwSize);
try
if IcmpSendEcho(hICMP,MAKELONG(MAKEWORD(StrToInt(Class1), StrToInt(Class2)),MAKEWORD(StrToInt(Class3), StrToInt(Class4))),
nil,0,
nil,pierWork,dwSize,TimeOut) = 0
then
Result:=False
else
Result:=True;
finally
FreeMem(pierWork,dwSize);
end;
finally
IcmpCloseHandle(hIcmp);
end;
end;