简体   繁体   中英

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. 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.

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:

显示 IP 地址的控制台。

It's done an incredible job of exposing my 3 IPs, my local IPv6, temporary IPv6, and my IPv4, just duplicated. 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.

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.

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). Is this common? Thanks!

This has to do with what @SeanDuBois said in the comments. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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