问题
I know there are some web sites that provide this service but given that pretty much everyone lives behind NAT these days, why isn't this standardized on a port and provided as a service to whomever wants to run it? It's at least as useful as an echo, daytime or "quote of the day" server and as easy to implement.
Or does one exist that I am aware of? Any proposals/RFCs in progress?
EDIT: Thanks to everyone for a lively and thoughtful discussion.
回答1:
It's standarised with the STUN protocol in RFC 5389
Of course, vendors have to support standards to make them useful.
Related threads on StackOverflow. They all mention STUN:
- Discovering public IP programatically
- Trying to get NAT’s external IPAddress with INATExternalIPAddressCallback in C#
- Obtaining Own External IP Address in POSIX C
回答2:
You really need more than to know what your IP address is "right now". You need to have it stay that way.
More importantly, it seems that the reason you need to know your IP address is that you need to tell some other machine how to connect to you. What's really needed, then, isn't a low-level hack, but rather some protocol that configures all interested Network-layer devices to make sure that you can be reached, and that the connection stays open (or that it can reconnect if broken).
For instance, it's possible for your router to lose its connection to your ISP. When it gets a new connection, it could have a different IP address. You need to address that problem. In a Corporate environment (yes, corporations do use P2P), any number of network reconfigurations may take place, all without informing the peers about changes in IP address. This needs to be addressed as well.
The overall problem is that you're depending on a Network-layer entity (IP Address) to remain useful for the upper layers. That's not the job of an IP address - it's only meant to get your datagrams to their destination. There's nothing inherent in knowing your IP address that says they'll still get to their destinations tomorrow by using that same address.
回答3:
If such a peername service existed, your NAT gateway could choose to modify the service's response, replacing the external address with the internal one, again.
Also, in case of a double-natted system: how would you get at the middle address?
回答4:
There's going to be no widespread fix. 'When/if IPv6 ever fully replaces IPv4 then the abundance of available addresses will make NAT, and thus this issue, a thing of the past.
来源:https://stackoverflow.com/questions/1178402/why-no-whats-my-ip-well-known-port-service