Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

How do I check if an IP Address exists or not

Title: How do I check if an IP Address exists or not? This function uses the Indy Clients, and checks if a given IP Address is valid or not by Pinging that IP. If it receives anything back, it returns true, or else if it does not get a reply, it returns false. CODE unit IPVerify; interface uses IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient, Windows, Messages, Classes, SysUtils; function IPExists(IPAddr: String): Bool; implementation function IPExists(IPAddr: String): Bool; var I: TIdIcmpClient; Rec: Integer; begin Result:= False; I:= TIdIcmpClient.Create(nil); try I.Host:= IPAddr; I.Ping(); Sleep(2000); Rec:= I.ReplyStatus.BytesReceived; if Rec 0 then Result:= True else Result:= False; finally I.Free; end; end; end.