11-30-2011 12:21 AM
Hello,
If a machine will connect to my machine through several gateways, can I use the "GetTCPPeerAddr()" function to get its IP address?
David
11-30-2011 09:03 AM
Yes.
11-30-2011 09:09 AM
Note that you can only get the IP address of the node (router) that is connected to the internet. The intranet IP address assigned to the machine by the router will not be available.
11-30-2011 09:34 AM
Well, your means that I can just get the router's IP address, but how to get the outer machine's IP address?
12-01-2011 09:58 AM
You cannot get the private IP address assigned by the router to the machine from other machines that are not on your private network. The private address is not unique on the internet and it will not be visible on the internet. If you want the machine's IP address to be available on the internet, then you should connect the machine directly to the internet (your ISP - Internet Service Provider) without going through a router. This way, your machine should get an IP address from your ISP that is unique and visible on the internet.
Note, that when your machine is connected to a router, even if the other machine gets the private address of your machine, this address would be useless as it does not uniquely identify your machine. If all you want is a way to identify the machine, just generate a GUID or some other unique identifier and send this to the other machine as a TCP message.