为 NAT 后面的主机检索外部 IP 的稳定方法
基本上我想显示主机外部面向公众的 IP 地址,无论它是否是 natted lan 的一部分。我现在所做的只是连接到 myipaddress.com 并从那里检索它。我只是不知道我是否信任该网站作为稳定的来源。是否有一些权威机构可以促进这一点?
Basically I want to display a hosts external public facing IP address regardless of whether or not it is part of a natted lan. What I'm doing now is just connecting to myipaddress.com and retrieving it from there. I just don't know if I trust that site as a stable source. Is there some authority that facilitates this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
公共互联网上的每个网络服务器都会自动看到您的外部 IP 地址。据我所知,没有标准化的方法来“反驳”(例如通过标题或其他东西)。
如果您想手动执行此操作,只需使用众多“我的 IP 是什么?”之一即可。 www.infobyip.com/detectmyip.php 等服务
如果您想以自动化方式执行此操作,最稳定的方法是在远程服务器上设置脚本,并让其输出请求者的 IP。在 PHP 中,大多数情况下,它看起来像这样:
(这里详细讨论了如何以各种方式检索IP,但如果上述方法对您一次有效,那么它很可能永远有效。)
Every web server on the public internet automatically sees your external IP address. There is just no standardized way to "talk it back" as far as I know (e.g. through a header or something).
If you want to do this manually, just use one of the numerous "what's my IP?" services around like www.infobyip.com/detectmyip.php
If you want to do it in an automated fashion, the most stable way would be to set up a script on a remote server, and have that output the requester's IP. In PHP, in most cases, it would look like so:
(Here is a detailed discussion on how to retrieve the IP in various ways, but if the above worked for you once, it is likely to work forever.)
STUN RFC 3489 可以做到这一点,尽管您需要访问开放的 STUN 服务器。还有其他网站(例如 myipaddress.com)会向您报告您的明显地址,但没有为此提供“标准”服务。
STUN RFC 3489will do it, though you need access to an open STUN server. There are other sites (like myipaddress.com) that will report your apparent address back to you, but there is no "standard" service for this.