[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Indy 10 ping - responds to its own pings!

Posted on 2006-05-15
9
Medium Priority
?
3,412 Views
Last Modified: 2012-06-27
One PC, two network connections through a switch to a remote machine. Need to be able to connect through either link for redundancy - and I need to know if one or the other fails. Although we won't be pinging in the final version, I just want a sanity check for now - and pinging is easy to use without having to run some client software on the other end.

Playing about with Indy, I see I can use the IdIcmpClient component to ping another machine. Great. Except I always get an echo back from ITSELF! Binding to a particular adaptor does not work. Am I missing something fundamental here?

Here's the relevant part of the code:
procedure TForm1.Button1Click(Sender: TObject);
begin
      IdIPAddrMon1.ForceCheck;
      Memo1.Lines.Add(IntToStr(IdIPAddrMon1.AdapterCount));
      Memo1.Lines.AddStrings(IdIPAddrMon1.IPAddresses);

      Timer.Enabled := true;
end;

procedure TForm1.IdIcmpClient1Reply(ASender: TComponent;
      const AReplyStatus: TReplyStatus);
begin
      case AReplyStatus.ReplyStatusType of
            rsEcho:      Memo1.Lines.Add(IdIcmpClient1.Binding.IP + ' echo');
            rsTimeOut:      Memo1.Lines.Add(IdIcmpClient1.Binding.IP + ' timeout');
      else
            Memo1.Lines.Add(IdIcmpClient1.Binding.IP + ' general error');
      end;
      Memo1.Lines.Add(IntToStr(AReplyStatus.BytesReceived) + ' bytes from ' + AReplyStatus.FromIpAddress + ' to ' +AReplyStatus.ToIpAddress);
end;

procedure TForm1.TimerTimer(Sender: TObject);
begin
      Toggle := not Toggle;
      if Toggle then begin
            IdIcmpClient1.Binding.SetBinding(IdIPAddrMon1.IPAddresses[1], IdIcmpClient1.Port);
      end else begin
            IdIcmpClient1.Binding.SetBinding(IdIPAddrMon1.IPAddresses[0], IdIcmpClient1.Port);
      end;
      IdIcmpClient1.Ping('191.168.100.7');
end;

Here's the output:
192.168.1.2 echo
1044 bytes from 192.168.100.219 to 192.168.100.219
192.168.100.219 echo
1044 bytes from 192.168.100.219 to 192.168.100.219
192.168.1.2 echo
1044 bytes from 192.168.100.219 to 192.168.100.219
192.168.100.219 echo
1044 bytes from 192.168.100.219 to 192.168.100.219

As you can see, it's pinging FROM and TO the SAME address! By the way, 192.168.100.7 doesn't even exist. Yes, I have administrator priviledges.

Thoughts?

Thanks

Geoff M.
0
Comment
Question by:gmayo
  • 4
  • 3
  • 2
9 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 16683024
you don't need to bind to anyhting. take a look at this example here: http://www.ciuly.com/delphi/indy/gatewayPinger/index.html and you will see how it si done :)
0
 
LVL 8

Author Comment

by:gmayo
ID: 16683261
How do I know which card I'm pinging through? I can't see anything in your code that differentiates between the different cards, which therefore fails the 2nd sentence of my request.

Thanks

Geoff M.
0
 
LVL 28

Expert Comment

by:2266180
ID: 16683362
well, if your network card #1 is 192.168.x.y with default gateway 192.168.a.b and your network card #2 is 10.x.y.z with default gateway 10.a.b.c, then, if you ping 192.168.m.n it will go through network #1, and if you ping 10.m.n.p through network #2 by default.
I never had 2 network interfaces that have ip's in the same class. I'll have to dig a little on that.
but if I look at your code:
IdIcmpClient1.Binding.SetBinding(IdIPAddrMon1.IPAddresses[1], IdIcmpClient1.Port);
might not be a good idea to do. try to do a
IdIcmpClient1.Binding.clear; first and then add the necessary binding from a bindings list kept separatly (not in the component)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16687114
Don't you just go

     if Toggle then begin
          IdIcmpClient1.Port := IdIPAddrMon1.IPAddresses[1], IdIcmpClient1.Port;
     end else begin
          IdIcmpClient1.Port := IdIPAddrMon1.IPAddresses[0], IdIcmpClient1.Port;
?
0
 
LVL 8

Author Comment

by:gmayo
ID: 16688483
The RealLoki, what? That doesn't make syntactical sense...

Geoff M.
0
 
LVL 8

Author Comment

by:gmayo
ID: 16688589
Hmm, ciuly, you have a point about pinging a certain destination will go through whichever card is necessary, but the actual system uses multicasting so I'm not sure whether that applies or not.

In fact I was trying on my wireless laptop with a wired connection - but it turns out only the wireless connection will ping (even using DOS prompt). The target machines have different subnet masks and different IP addresses - they can't both use the same subnet mask.

However,
IdIcmpClient1.Binding.Clear - no such method

IdIcmpClient1.Ping('191.168.100.7');
- is complete bollocks - I should have written:
IdIcmpClient1.Host := '192.168.100.7';
IdIcmpClient1.Ping;

Doh!

Geoff M.
0
 
LVL 28

Accepted Solution

by:
2266180 earned 140 total points
ID: 16688689
hm .. sorry. that is for sever components :) my bad
I did however look in the indy help and found that:
Binding is a read-only TIdSocketHandle property that represents the socket handle used for a connection to another computer system.
so setting the binding to the ip of your machine will inded ping your machine :)

however
property BoundIP: string;
Description
BoundIP is a String property that specifies the local IP address to be used for the client connection.
seems to do what you want.
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 16694724
sorry, i was just cut & pasting your code
my question was, do you actually need to set the binding manually, or do you just set the IdIcmpClient1.Port property
0
 
LVL 8

Author Comment

by:gmayo
ID: 16715996
TheRealLoki, you can't have copied my code because mine at least compiled, unlike yours! :-p

Ping doesn't use a port number. I was using the number already assigned because, to assign an IP, you also have to specify a port number.

Cheers

Geoff M.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question