【问题标题】:Some clients cannot get their IP after updating Chrome部分客户端更新 Chrome 后无法获取 IP
【发布时间】:2023-03-13 06:14:01
【问题描述】:
  • 使用 Chrome 版本 75.0.3770.100 64bit 的客户端:有些可以提供有效的 IP,有些则不能(请参阅下面的有效或无效示例)

我尝试过的: (p.s. x 是下面的数字) 1. 客户端提供的 IP 无效:卸载 Chrome -> 更新到旧版本:71.0.3578.80 64bit (获得有效的 Ip,例如 1x2.1x.2.x1)

  1. 无效 IP 提供的客户端:卸载 Chrome -> 更新到旧版本 -> 更新回最新版本:75.0.3770.100 64 位 -> 重新启动计算机(不起作用,获取无效 ip:候选:7x3x0x8x0 1 udp 21x3x3x1x1 31xcxece-ax6f -x3f2-abx9-f1f4fb9x5x6x.local 4xx1x typ host generation 0 ufrag Bkiq network-cost 999)

代码:

    //compatibility for firefox and chrome
    var myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
    var pc = new myPeerConnection({
        iceServers: []
    }),
    noop = function() {},
    localIPs = {},
    ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g,
    key;

    function iterateIP(ip) {
        if (!localIPs[ip]) onNewIP(ip);
        localIPs[ip] = true;
    }

     //create a bogus data channel
    pc.createDataChannel("");

    // create offer and set local description
    pc.createOffer().then(function(sdp) {
        sdp.sdp.split('\n').forEach(function(line) {
            if (line.indexOf('candidate') < 0) return;
            line.match(ipRegex).forEach(iterateIP);
        });

        pc.setLocalDescription(sdp, noop, noop);
    }).catch(function(reason) {
        // An error occurred, so handle the failure to connect
    });

    //listen for candidate events
    pc.onicecandidate = function(ice) {
        return ice.candidate.candidate; // comment below, as it will return nothing as the ip does not match the ipRegex
        // if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex)) return;
        // ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
    // };
}

// Usage

getUserIP(function(ip){
    alert("Got IP! :" + ip);
});

希望即使更新到最新版chrome(75.0.3770.100 64bit)所有客户都能提供有效ip

【问题讨论】:

    标签: javascript google-chrome ip


    【解决方案1】:

    iceServers 配置中使用 stun/turn server ips/domains 而不是空的,例如{ "iceServers": [ { urls: 'stun:stun.l.google.com:19302' } ] }。当客户端在不同的网络上时,Stun/turn 服务器是必要的。

    【讨论】:

      【解决方案2】:

      我找到了一个解决方案,让用户 ip 在更新最新的 chrome 后可以发送回服务器:

      1. 用户转到 chrome://flags
      2. 搜索“匿名化由 WebRTC 公开的本地 IP”。使用 mDNS 主机名隐藏本地 IP 地址。 – Mac、Windows、Linux、Chrome 操作系统
      3. 禁用它

      【讨论】:

        【解决方案3】:

        这不是错误,这是正常的,因为您将来将无法以这种方式获取地址。

        WebRTC 主机候选者现在将使用随机 mDNS 主机名匿名化,以防止网站转移 WebRTC 以窥探本地 IPv4 地址。逐渐为所有 Chrome 用户启用该行为。它也在 Firefox 中实现。

        以下是 ChromiumFirefox 的相应错误,以及当前用于 WebRTC mDNS 候选者的 IETF draft

        【讨论】:

          猜你喜欢
          • 2012-09-30
          • 1970-01-01
          • 2012-10-14
          • 2015-09-01
          • 2020-12-08
          • 1970-01-01
          • 2012-09-25
          • 2013-10-16
          • 2014-10-06
          相关资源
          最近更新 更多