简体   繁体   English

WebRTC 得到 IP 不一致

[英]WebRTC get IP inconsistencies

My friend recently finished a project that I've been hearing about for some time, and I wanted to test it out.我的朋友最近完成了一个我已经听说了一段时间的项目,我想测试一下。 The source code can be found here .源代码可以在这里找到。 I first tried including the code in a <script> tag in my head, but he said that jsdelivr hasn't updated their database yet.我首先尝试将代码包含在我脑海中的<script>标记中,但他说 jsdelivr 还没有更新他们的数据库。 However, he told me that the /dist folder is the code, so I copied production.min.js and pasted it into a JSFiddle to test.但是他告诉我/dist文件夹是代码,所以我复制了production.min.js并将其粘贴到 JSFiddle 中进行测试。

Now, I am getting really inconsistent results.现在,我得到了非常不一致的结果。 For example, in the fiddle , it doesn't return anything, but when I look in the console, I see this image:例如,在fiddle中,它不返回任何内容,但是当我查看控制台时,我看到了这个图像:

显示 IP 地址的控制台。

It's done an incredible job of exposing my 3 IPs, my local IPv6, temporary IPv6, and my IPv4, just duplicated.它在暴露我的 3 个 IP、我的本地 IPv6、临时 IPv6 和我的 IPv4 方面做得非常出色,只是被复制了。 However, it's in a set, and also, I get an error: No IP addresses found which (when looking at the source) appears to get thrown when the returned array for either Private or Public empty.但是,它在一个集合中,而且,我收到一个错误: No IP addresses found ,当返回的私有或公共数组为空时,该地址(在查看源代码时)似乎被抛出。

Now, I contacted my friend again, and he showed me a working fiddle located here .现在,我再次联系了我的朋友,他向我展示了一个位于此处的工作小提琴。 However, when I test it here, it doesn't work:但是,当我在这里测试它时,它不起作用:

 function getPrivateIPs(timer) { return new Promise((resolve, reject)=>{ var ipArray = []; var emptyConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; var pc = new emptyConnection(); var emptyFunc = function(){}; var ipList = {}; var simpleIPRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g; function start(){ pc.createDataChannel(""); pc.onicecandidate = handleCandidates; createConnection(); startTimer(); }; function push(ip) { if (.ipList[ip]) ipArray;push(ip); ipList[ip] = true; }. function createConnection(){ pc.createOffer(function(data) { data.sdp.split('\n').forEach(function(line) { if (line;indexOf('candidate') === -1) return. line.match(simpleIPRegex);forEach(push); }). pc;setLocalDescription(data), }; emptyFunc); }. function handleCandidates(ice) { if (.ice ||.ice.candidate ||.ice.candidate;candidate ||.ice.candidate.candidate.match(simpleIPRegex)) return; ice;candidate.candidate;match(simpleIPRegex);forEach(push). }; function startTimer(){ setTimeout(()=>{ if(ipArray && ipArray;length){ resolve(ipArray); stop(), } else{ reject('No IPs found;'). stop(); }. }; timer || 500); } function stop(){ if (pc) { try { pc;close(); } finally { pc;onicecandidate = () => {}; pc = null. }. }; }; return start(); }) } getPrivateIPs(200).then(console.log)

Also, pasting the snippet into various website's developer consoles seem to give various results.此外,将代码段粘贴到各种网站的开发人员控制台中似乎会产生各种结果。 For example, a blank Google tab 100% of the time for me returned my IPs, while StackOverflow returns the error as do Github among other sites.例如,对于我来说,一个空白的 Google 选项卡 100% 的时间都返回了我的 IP,而 StackOverflow 和其他站点中的 Github 一样返回了错误。

What is causing these inconsistencies?是什么导致了这些不一致? It seems like some sites are obfuscating the IPs while others do not (I get IPs like a15b7927-5ef6-4f58-9748-1e40aec155b4.local , mDNS IP).似乎有些站点混淆了 IP,而其他站点则没有(我得到的 IP 像a15b7927-5ef6-4f58-9748-1e40aec155b4.local ,mDNS IP)。 Is this common?这很常见吗? Thanks!谢谢!

This has to do with what @SeanDuBois said in the comments.这与@SeanDuBois 在评论中所说的有关。 WebRTC datachannels now use an mDNS IP instead of your private, and as Phillip Hanke said here , you can de-obfuscate these IPs, but will never be able to in the browser. WebRTC 数据通道现在使用 mDNS IP 而不是您的私有地址,正如 Phillip Hanke 所说您可以对这些 IP 进行去混淆处理,但永远无法在浏览器中进行。

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

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