Te muestro una Unit simple para hacer ping por código. Te permite direcciones en formato IP o Web:
Código Delphi
[-]
unit UPing;
interface
uses
Windows, WinSock;
function IcmpCreateFile: Integer; stdcall external 'iphlpapi'
function IcmpSendEcho(Handle, Address: Integer; RequestData: PChar; RequestSize: Word; RequestOptions, ReplyBuffer: PChar; ReplySize, TimeOut: Cardinal): Cardinal; stdcall external 'iphlpapi';
function IcmpCloseHandle(IcmpHandle: Cardinal): boolean; stdcall external 'iphlpapi'
function Ping(Addr: PCHAR; Rep: integer = 3): boolean;
type
ICMP_OPTION_INFORMATION = packed record
Ttl: u_char;
Tos: u_char;
Flags: u_char;
OptionsSize: u_char;
OptionsData: Pointer;
end;
PICMP_OPTION_INFORMATION= ^ICMP_OPTION_INFORMATION;
ICMP_ECHO_REPLY = packed record
Address: Cardinal;
Status: Cardinal;
RoundTripTime: Cardinal;
DataSize: Word;
Reserved: Word;
Data: Pointer;
Options: ICMP_OPTION_INFORMATION;
end;
PICMPP_ECHO_REPLY = ^ICMP_ECHO_REPLY;
implementation
function Ping(Addr: PCHAR; Rep: integer = 3): boolean;
var
WSA: TWSAData;
hIcmpFile: Cardinal;
Reply: ICMP_ECHO_REPLY;
He: Phostent;
begin
Result:= false;
if WSAStartup(MAKEWORD(1, 1), WSA) <> 0 then exit;
He:= gethostbyname(Addr);
if He = nil then exit;
hIcmpFile:= IcmpCreateFile;
repeat
Result:= IcmpSendEcho(hIcmpFile, PULONG(He.h_addr_list^)^, 0, 0, 0, PCHAR(@Reply), sizeof(ICMP_ECHO_REPLY), 1000) <> 0;
Result:= Result and (Reply.Status = 0); dec(Rep);
until Result or (Rep = 0);
IcmpCloseHandle(hIcmpFile);
WSACleanup;
end;
end.
Saludos.