WinScok
function TIPManageRdm.PingIP(const IPAddr: WideString): OleVariant;
Var
Msg:String;
wVersionRequested : WORD;
wsaData : TWSAData;
PEvt : PHostEnt;
HostName : array[0..128] of char;
pHostName
char;
pIPAddress
char;
begin
HostName:='';{Init String}
pHostName:=@HostName;
StrPCopy(pHostName,IPAddr);{IPAddr is Computer Name Or Computer IP Address}
{Open WinSock}
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
{Get Computer Name}
PEvt := GetHostByName(pHostName);
if pEvt=nil then
begin
Msg:='Unknown the Host!';
end
else
begin
//ShowMessage(Format('Computer name is ''%s''.', [pEvt^.h_Name]));
{Get IP Address}
pIPAddress := iNet_ntoa(PInAddr(pEvt^.h_addr_list^)^);
//ShowMessage(Format('IP address is %s.',[pIPAddress]));
{Get Computer Name if IPAddr is Computer IP Address}
pEvt:=Winsock.gethostbyaddr(pEvt^.h_addr_list^,0,0);
//ShowMessage(Format('Computer name is ''%s''.', [pEvt^.h_Name]));
if PEvt=nil then
begin
Msg:='Unknown Host Name!';
end
else
begin
Msg:=Format('<h3>Computer name is "%s" .</h3><br>',[pEvt^.h_Name]);
Msg:=Msg+Format('<h3>IP address is %s</h3><br>',[pIPAddress]);
With self.IPCheck do
begin
Host:=IPAddr;
Try
Ping;
With ReplyStatus do
begin
Msg:=Msg+Format('%d bytes from %s: icmp_seq=%d ttl=%d time=<%d ms',[BytesReceived,FromIpAddress,SequenceId,TimeToLive,MsRoundTripTime]);
end;
except
Msg:=Msg+' Ping Error!';
end;
end;
end;
end;
Result:=Msg;
end;