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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi network starting 1

Status
Not open for further replies.

jfreak53

IS-IT--Management
Apr 30, 2004
44
0
0
GT
I need to make a small program that checks certain ip addresses on my personal network every certain number of seconds to see if they are connected to the network, maybe a ping? I was told that Indy components have this feature but I cannot find it, I use delphi 6.
 
J-

I would use a listbox or memo instead of a label. A label has a "finite" area to show something in "caption". With a listbox or memo you can "clear" it at the start of the loop and "add" lines when you find one is connected.



Regards and HTH,
JGS
 
Should you still be wondering what Indy component it is, it's the idICMP component which has the ping functionality.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Ok, thanks but how do I add then when they appear as connected to the list?
 
You could use it like this:
Code:
TForm1.Button1Click(Sender: TObject);
begin
IdICMPClient1.Host := 192.168.0.101;
IdICMPClient1.Port := 2346;
IdICMPClient1.ReceiveTimeOut := 500;
IdICMPClient1.Ping();
end;

procedure TForm1.IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus);
begin
if (AReplyStatus.ReplyStatusType = rsTimeOut) or (AReplyStatus.ReplyStatusType = rsErrorUnreachable) then
        begin
        ShowMessage('Computer is down.');
        end
        else
        begin
        ShowMessage('Packet round trip time: ' + IntToStr(AReplyStatus.MsRoundTripTime) + ' ms.');
        end;
end;

Hope this helps,

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Ok, that would work for the other version, but I want a running list made of connected ip's?
 
you could create a stringlist with all the possible IP's, loop through them with pings and create a new stringlist with all the active ones.

Code:
private
ActiveIPList, AllIPList: TStringList;

procedure TForm1.FillAllIPList;
begin
// Some way to fill the list with IP's
AllIPList.Add('192.168.0.101');
AllIPList.Add('192.168.0.102');
AllIPList.Add('192.168.0.103');
AllIPList.Add('192.168.0.104');
AllIPList.Add('192.168.0.105');
AllIPList.Add('192.168.0.106');
AllIPList.Add('192.168.0.107');
AllIPList.Add('192.168.0.108');
AllIPList.Add('192.168.0.109');
AllIPList.Add('192.168.0.110');
end;

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
FillAllIPList;
for i := (AllIPList.Count - 1) downto 0 do
        begin
        IdICMPClient1.Host := AllIPList.Strings[i];
        IdICMPClient1.Port := 80;
        IdICMPClient1.ReceiveTimeOut := 500;
        IdICMPClient1.Ping();
        end;
end;

procedure TForm1.IdIcmpClient1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus);
begin
if (AReplyStatus.ReplyStatusType <> rsTimeOut) and (AReplyStatus.ReplyStatusType <> rsErrorUnreachable) and (AReplyStatus.FromIpAddress <> '0.0.0.0') then
        begin
        ActiveIPList.Add(AReplyStatus.FromIpAddress);
        end;
end;

The ip 0.0.0.0 occurs when you get any other error than ErrorUnreachable.

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top