简体   繁体   English

LAN IP地址的JavaScript检测

[英]JavaScript detection of LAN IP address

I have been using the following code to detect the LAN IP address of a client running some proprietary software (please no "you shouldn't do this", I didn't write the code). 我一直在使用以下代码来检测运行某些专有软件的客户端的LAN IP地址(请不要“我不应该这样做”,我没有编写代码)。

function ip_local()
{
 var ip = false;
 window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || false;

 if (window.RTCPeerConnection)
 {
  ip = [];
  var pc = new RTCPeerConnection({iceServers:[]}), noop = function(){};
  pc.createDataChannel('');
  pc.createOffer(pc.setLocalDescription.bind(pc), noop);

  pc.onicecandidate = function(event)
  {
   if (event && event.candidate && event.candidate.candidate)
   {
    var s = event.candidate.candidate.split('\n');
    ip.push(s[0].split(' ')[4]);
   }
  }
 }

 return ip;
}
ip_local();

Which is from another StackOverflow post, the code has been working fine for a year and a half up until this afternoon. 这是从另一个StackOverflow帖子中获得的,直到今天下午,该代码已经可以正常工作一年半了。

Where as my local ip seems to be detected as 153b3a68-e3fb-4451-9717-d9b3bc2b5c60.local instead of the usual 192.168.0.11. 我的本地IP似乎被检测为153b3a68-e3fb-4451-9717-d9b3bc2b5c60.local,而不是通常的192.168.0.11。

Edit: If anyone cares, this issue is NOT bypassable and has to be done via a server side language, in my case I ended up using PHP as a temporary "bandaid" over the problem. 编辑:如果有人在乎,这个问题是无法绕过的,必须通过服务器端语言来完成,就我而言,我最终将PHP用作问题的临时“创可贴”。

This is a problem for my app as it detects whether a local server is running on the host.. Which it cannot do if it cannot detect the LAN IP address. 这对我的应用程序来说是个问题,因为它会检测主机上是否正在运行本地服务器。如果无法检测到LAN IP地址,它将无法执行此操作。

This is part of a new security standard, to prevent leakage of private IP addresses. 这是新安全标准的一部分,可以防止私有IP地址泄漏。

See also: https://tools.ietf.org/html/draft-ietf-rtcweb-mdns-ice-candidates-02 另请参阅: https : //tools.ietf.org/html/draft-ietf-rtcweb-mdns-ice-candidates-02

Summary: 摘要:

As detailed in [IPHandling], exposing client private IP addresses by default maximizes the probability of successfully creating direct peer-to-peer connection between two clients, but creates a significant surface for user fingerprinting. 如[IPHandling]中的详细说明,默认情况下公开客户端专用IP地址可最大程度地提高在两个客户端之间成功建立直接对等连接的可能性,但会为用户指纹创建重要的表面。 [IPHandling] recognizes this issue, but also admits that there is no current solution to this problem; [IPHandling]认识到此问题,但也承认目前没有解决此问题的方法; implementations that choose to use Mode 3 to address the privacy concerns often suffer from failing or suboptimal connections in WebRTC applications. 选择使用模式3解决隐私问题的实现通常会遭受WebRTC应用程序中连接失败或连接欠佳的困扰。 This is particularly an issue on unmanaged networks, typically homes or small offices, where NAT loopback may not be supported. 在非托管网络(通常是家庭或小型办公室)中,这尤其是个问题,在这些网络中可能不支持NAT环回。

This document proposes an overall solution to this problem by registering ephemeral mDNS names for each local private IP address, and then providing those names, rather than the IP addresses, to the web application when it gathers ICE candidates. 本文档通过为每个本地私有IP地址注册临时mDNS名称,然后在收集ICE候选者时向Web应用程序提供这些名称而不是IP地址,来提出针对此问题的整体解决方案。 WebRTC implementations resolve these names to IP addresses and perform ICE processing as usual, but the actual IP addresses are not exposed to the web application. WebRTC实现将这些名称解析为IP地址,并照常执行ICE处理,但实际的IP地址未公开给Web应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM