-2

Sorry for the noob question, but I'm trying to hack together an ad hoc dynamic dns to reliably connect two machines in different geographic regions. My issue is every command I try (ifconfig, iwconfig, netstat, etc.) gives me the IP address from behind the subnet (so for example 10.0.0.1) but I need to be able to tell the other machine what my current external IP is, not what it is to the other machines on my subnet. How can I do this?

Bonus points for tips on how to do it in Python

syzygy
  • 101
  • 1
  • How do you plan on connecting them once you have the external IPs? Do you plan to open ports on firewalls to allow the inbound traffic between the 2 somehow? Getting the external IP is one thing...getting the 2 to talk afterwards is another. – TheCleaner Oct 07 '13 at 13:07

2 Answers2

3

If this device is behind a NAT, there is no way to do it. The NATted device does not know how its packets are being NATted en route - only the NATting device (firewall, router, whatever) knows this.

Edit: no, technically I mean it is unknowable, as you have defined the question. This sort of thing happens all the time. There is no way for your computer to know which generating authority is being billed for the electricity which powers that computer. It's not unknowable in principle, but there is no generally-valid technique that you can use from the computer concerned to find this information out, because the electrons don't have little labels on them saying who last gave them a push.

If your question is "how can I find out the generating authority", we can help; if it is "how can I find it out from my computer, without consulting external services", the question has no answer.

Similarly, if you'd asked "how do I find out what my computer's IP address is being NATted to", then we could help, as indeed Jenny D is above; the answer won't be generally-valid, and will depend on the brand of NAT device, the access arrangements it currently supports, and so on (though that question is probably off-topic for Server Fault, and would probably get closed, even as this one might). But you asked "how does my computer find out what its IP address is being NATted to", and that question has no general answer.

As for how not to get downvoted, you could do much worse than to read and inwardly digest our help document on asking good questions.

MadHatter
  • 78,442
  • 20
  • 178
  • 229
  • Technically, you mean you don't know how to do it. That doesn't mean there isn't a way. The only way to be certain of the absence of something is to be aware of all things. Anyways, thanks for answering. Any tips on how not to get downvoted in the future? – syzygy Oct 07 '13 at 08:50
2

If you do not have access to the firewall/router/whatever, you would need to have some device outside of your own network that could give you the answer to that question. You might put something together that would scrape e.g. http://www.whatismyip.com/ - but it would not be reliable unless you own or pay for the remote service

Jenny D
  • 27,358
  • 21
  • 74
  • 110
  • Thanks! What if I do have access to the router? What could I do then? – syzygy Oct 07 '13 at 08:42
  • You would need to know how to ask it for the external IP address. I'd start by reading the manual for your particular router. – Jenny D Oct 07 '13 at 08:52
  • I decided to scrape and pass thru awk, it worked! Thanks a bunch. I'd totally upvote you if I could... – syzygy Oct 07 '13 at 09:47