你能通过JavaScript获得用户本地局域网IP地址吗? [英] Can You Get A Users Local LAN IP Address Via JavaScript?

查看:271
本文介绍了你能通过JavaScript获得用户本地局域网IP地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道对这个问题的最初反应是不和它无法完成和你不应该需要它,你做错了什么。我要做的是获取用户的LAN IP地址,并将其显示在网页上。为什么?因为这就是我正在处理的页面,尽可能多地显示关于你的信息,访问者:
http://www.whatsmyip.org/more-info-about-you/

I know the initial reaction to this question is "no" and "it can't be done" and "you shouldn't need it, you are doing something wrong". What I'm trying to do is get the users LAN IP address, and display it on the web page. Why? Because that's what the page I'm working on is all about, showing as much information as possible about you, the visitor: http://www.whatsmyip.org/more-info-about-you/

所以我实际上并没有做任何事情使用IP,除了向用户显示以供参考之外。我曾经通过使用一个小的Java小程序来做到这一点。它工作得很好。但是现在,浏览器会让你多次同意和信任,甚至可以运行最小的java applet,我根本不会运行它。

So I'm not actually DOING anything with the IP, other than showing it to the user for informational purposes. I used to do this by using a small Java applet. It worked pretty well. But these days, browser make you hit agree and trust so many times, to run even the most minor java applet, that I'd rather not run one at all.

所以有一段时间我刚刚摆脱了这个功能,但如果可能的话我会想要它。作为一名计算机顾问,我不时会实际使用它。访问此网站以查看网络运行的IP范围比进入系统偏好设置,网络连接以及任何活动界面更快。

So for a while I just got rid of this feature, but I'd like it back if possible. It was something that I, as a computer consultant, would actually use from time to time. It's faster to go to this website to see what IP range a network is running on, than it is to go into System Preferences, Networking, and then whatever interface is active.

所以我想知道,如果有一些方法可以单独在javascript中完成它吗?也许你可以访问一些新对象,类似于javascript可以询问浏览器在地球上的地理位置的方式。也许客户网络信息有类似之处?如果没有,也许还有其他一些方法可以完成吗?我能想到的唯一方法是java applet或flash对象。我宁愿不做其中任何一个。

So I'm wondering, hoping, if there's some way to do it in javascript alone? Maybe some new object you can access, similar to the way javascript can ask the browser where is geographic location on earth is. Maybe theres something similar for client networking information? If not, perhaps theres some other way entirely to do it? The only ways I can think of are a java applet, or a flash object. I'd rather not do either of those.

推荐答案

事实证明,HTML5最近的WebRTC扩展允许javascript查询本地客户端IP地址。此处提供了概念验证: http://net.ipcalf.com

As it turns out, the recent WebRTC extension of HTML5 allows javascript to query the local client IP address. A proof of concept is available here: http://net.ipcalf.com

此功能显然是按设计,并不是错误。但是,鉴于其有争议的性质,我会谨慎依赖这种行为。尽管如此,我认为它完全适当地解决了您的预期目的(向用户透露他们的浏览器漏洞)。

This feature is apparently by design, and is not a bug. However, given its controversial nature, I would be cautious about relying on this behaviour. Nevertheless, I think it perfectly and appropriately addresses your intended purpose (revealing to the user what their browser is leaking).

这篇关于你能通过JavaScript获得用户本地局域网IP地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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