Javascript - 简单 - 从 URL 获取 Ip

发布于 2024-12-29 12:10:50 字数 263 浏览 2 评论 0原文

我只是想实现这样的目标:

function getIp() {
var urlenter = document.getElementById('io');
var IPOUT = urlenter.IpAdress !------HERE!!!!!!!!------!

location.href = IPOUT;
}

所以如果我在“io”中输入“facebook.com”,它会将 href 设置为 facebook.com 的 IP 地址

I am simply trying to achieve something like this:

function getIp() {
var urlenter = document.getElementById('io');
var IPOUT = urlenter.IpAdress !------HERE!!!!!!!!------!

location.href = IPOUT;
}

so if I typed 'facebook.com' in 'io' it would set the href to the ip adress of facebook.com

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚笙 2025-01-05 12:10:51

JavaScript 没有任何主机名或 IP 地址的概念。您必须使用外部服务从主机名解析 IP 地址。

JavaScript doesn't have any concept of hostnames or IP addresses. You would have to use an external service to resolve an IP address from a hostname.

情话难免假 2025-01-05 12:10:51

仅靠 JavaScript 是不可能实现这一点的。

IP 地址和主机名之间的解析是在 DNS 级别处理的,这早于 JavaScript 诞生。它只能知道所连接的主机,无论是通过实际主机名还是 IP 地址。

尽管如此,您仍然可以让 JavaScript 连接到外部服务(例如通过 Ajax 的服务器),并让它进行解析。

That's not possible with JavaScript alone.

The resolving between IP addresses and hostnames are handled at the DNS level, which is way before JavaScript ever comes to life. It only gets to know the host it is connected to, whether that is by an actual hostname or an IP address.

Still though, you could have JavaScript connect to an outside service, e.g. your server via Ajax, and have it make the resolving.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文