Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check IP Address Accessibility 1

Status
Not open for further replies.

djjd47130

Programmer
Nov 1, 2010
480
US
How would I go about making a function with one parameter (IP Address) which validates the existence of an IP Address? Something Like...

Code:
function IPExists(IPAddr: String): Bool;
begin
  Result:= False;
  //Some check which returns 'Result:= True' if IP is found
end;

JD Solutions
 
From your Indy Clients tab add a TIdIcmpClient to your form.
Add a Memo and a bitbtn to the form.
Add this to the bitbtnclick method:
Code:
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
   IdIcmpClient1.Host:= '127.0.0.1';
   idICMPClient1.Ping();
   Memo1.Lines.Add('Bytes received: ' +
                    IntToStr(idICMPClient1.ReplyStatus.BytesReceived));
end;
This pings your computer, you need to change the IP address to the computer you want to ping.
 
Easy enough, thank you. I know nothing about the Indy components, but I know they can do a lot. I've just never taken the time to play with them quite yet.

JD Solutions
 
I hear you, I haven't played with the Indy components that much either. I haven't found a good reference to the components yet, so if anyone knows of a good one, I would appreciate a link to it.
 
Here's what I've done with this:

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.

JD Solutions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top