From 5079f05d5bdcf6e486766dfbb6856d3c0ec70c78 Mon Sep 17 00:00:00 2001 From: Nulo Date: Sun, 5 Mar 2023 23:09:30 -0300 Subject: [PATCH] correctly parse non-numeric ip addresses correctly address mDNS addresses used to anonimize in desktop Chromium and Firefox --- index.html | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index f9edefd..f2d612c 100644 --- a/index.html +++ b/index.html @@ -58,10 +58,12 @@ var pc = new RTCPeerConnection(servers, mediaConstraints); function handleCandidate(candidate){ - //match just the IP address - var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/ - var ip_addr = ip_regex.exec(candidate)[1]; - + if (!candidate) return + //https://datatracker.ietf.org/doc/html/rfc5245#section-15.1 + console.debug(candidate) + const things = candidate.split(' ') + const ip_addr = things[4] + //remove duplicates if(ip_dups[ip_addr] === undefined) callback(ip_addr); @@ -71,7 +73,6 @@ //listen for candidate events pc.onicecandidate = function(ice){ - //skip non-candidate events if(ice.candidate) handleCandidate(ice.candidate.candidate); @@ -88,7 +89,7 @@ }, function(){}); - //wait for a while to let everything done + // wait for a while to let everything done setTimeout(function(){ //read candidate info from local description var lines = pc.localDescription.sdp.split('\n');