如何找出浏览器连接的服务器IP地址(使用JavaScript)? [英] How to find out the server IP address (using JavaScript) that the browser is connected to?

查看:108
本文介绍了如何找出浏览器连接的服务器IP地址(使用JavaScript)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以找到浏览器所连接的服务器的IP吗?对于例如如果浏览器正在访问 http://www.google.com ,我们能否以任何方式告知它是什么IP连接到?这在实施循环DNS 的情况下非常有用。因此,对 a.com 的第一个请求会产生 1.1.1.1 &后续请求结果 1.1.1.2 &等等。

Is there any way you can find the IP of the server that the browser is connected to? For e.g. if the browser is accessing http://www.google.com, can we tell in any way what IP it is connected to? This is very useful in cases where Round-robin DNS is implemented. So say, the first request to a.com results in 1.1.1.1 & subsequent request result in 1.1.1.2 & so on.

我找不到用JavaScript做任何事情的方法。它甚至可能吗?如果没有找到这个信息的通用方法吗?

I couldn't find any way to do it with JavaScript. Is it even possible? If not is there any universal way to find this info out?

推荐答案

相当确定无法做到这一点。但是,您可以使用首选的服务器端语言将服务器的IP打印到客户端,然后根据需要使用它。例如,在PHP中:

Fairly certain this cannot be done. However you could use your preferred server-side language to print the server's IP to the client, and then use it however you like. For example, in PHP:

<script type="text/javascript">
    var ip = "<?php echo $_SERVER['SERVER_ADDR']; ?>";
    alert(ip);
</script>

这取决于您服务器的安全设置 - 有些可能会阻止此操作。

This depends on your server's security setup though - some may block this.

这篇关于如何找出浏览器连接的服务器IP地址(使用JavaScript)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆