const
IP_SUCCESS = 0;
IP_BUF_TOO_SMALL = 11001;
IP_DEST_NET_UNREACHABLE = 11002;
IP_DEST_HOST_UNREACHABLE = 11003;
IP_DEST_PROT_UNREACHABLE = 11004;
IP_DEST_PORT_UNREACHABLE = 11005;
IP_NO_RESOURCES = 11006;
IP_BAD_OPTION = 11007;
IP_HW_ERROR = 11008;
IP_PACKET_TOO_BIG = 11009;
IP_REQ_TIMED_OUT = 11010;
IP_BAD_REQ = 11011;
IP_BAD_ROUTE = 11012;
IP_TTL_EXPIRED_TRANSIT = 11013;
IP_TTL_EXPIRED_REASSEM = 11014;
IP_PARAM_PROBLEM = 11015;
IP_SOURCE_QUENCH = 11016;
IP_OPTION_TOO_BIG = 11017;
IP_BAD_DESTINATION = 11018;
IP_GENERAL_FAILURE = 11050;
....
function Ping(InetAddress :
string;
var ErrorMessage :
String) : boolean;
var
Handle : THandle;
InAddr : IPAddr;
DW : DWORD;
PingBuf:
array[0..31]
of char;
Reply : ICMP_ECHO_REPLY;
begin
result := false;
ErrorMessage := '
';
try
DW := 0;
Handle := IcmpCreateFile;
if Handle = INVALID_HANDLE_VALUE
then
Exit;
try
TranslateStringToTInAddr(InetAddress, InAddr);
except
on E:
Exception do begin
ErrorMessage := e.
Message;
Exit;
end;
end;
Reply.Status := IP_SUCCESS;
Reply.Data := @pingBuf;
Reply.DataSize := 32;
DW := IcmpSendEcho(
Handle, InAddr, @PingBuf, 32,
nil, @reply, SizeOf(icmp_echo_reply) + 32 , 1500);
//Die 1000 gibt den TimeOut an
// if (Reply.Status <> IP_GENERAL_FAILURE) and (Reply.Status <> IP_SUCCESS) then
// ErrorMessage := Get_ICMP_ECHO_REPLY_StateString(reply.Status);
if DW <> 0
then begin
if Reply.Status = IP_SUCCESS
then begin
Result := True;
ErrorMessage := '
';
end;
end;
except
end;
IcmpCloseHandle(
Handle);
end;
// Ping