gpt4 book ai didi

JavaScript检测局域网IP地址

转载 作者:行者123 更新时间:2023-11-30 19:28:04 25 4
gpt4 key购买 nike

我一直在使用以下代码来检测运行某些专有软件的客户端的 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();

来自另一篇 StackOverflow 帖子,代码在今天下午之前已经正常运行了一年半。

因为我的本地 IP 似乎被检测为 153b3a68-e3fb-4451-9717-d9b3bc2b5c60.local 而不是通常的 192.168.0.11。

编辑:如果有人关心,这个问题是不可绕过的,必须通过服务器端语言来解决,在我的例子中,我最终使用 PHP 作为解决这个问题的临时“创可贴”。

这是我的应用程序的一个问题,因为它会检测本地服务器是否正在主机上运行。如果它无法检测到 LAN IP 地址,它就无法执行此操作。

最佳答案

这是新安全标准的一部分,用于防止私有(private) IP 地址泄露。

另请参阅:https://datatracker.ietf.org/doc/html/draft-ietf-rtcweb-mdns-ice-candidates-02

总结:

As detailed in [IPHandling], exposing client private IP addresses bydefault maximizes the probability of successfully creating directpeer-to-peer connection between two clients, but creates asignificant surface for user fingerprinting. [IPHandling] recognizesthis issue, but also admits that there is no current solution to thisproblem; implementations that choose to use Mode 3 to address theprivacy concerns often suffer from failing or suboptimal connectionsin WebRTC applications. This is particularly an issue on unmanagednetworks, typically homes or small offices, where NAT loopback maynot be supported.

This document proposes an overall solution to this problem byregistering ephemeral mDNS names for each local private IP address,and then providing those names, rather than the IP addresses, to theweb application when it gathers ICE candidates. WebRTCimplementations resolve these names to IP addresses and perform ICEprocessing as usual, but the actual IP addresses are not exposed tothe web application.

关于JavaScript检测局域网IP地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56711611/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com