correctly parse non-numeric ip addresses

correctly address mDNS addresses used to anonimize in desktop Chromium and Firefox
This commit is contained in:
Cat /dev/Nulo 2023-03-05 23:09:30 -03:00
parent ba63ef512c
commit 5079f05d5b

View file

@ -58,10 +58,12 @@
var pc = new RTCPeerConnection(servers, mediaConstraints); var pc = new RTCPeerConnection(servers, mediaConstraints);
function handleCandidate(candidate){ function handleCandidate(candidate){
//match just the IP address if (!candidate) return
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/ //https://datatracker.ietf.org/doc/html/rfc5245#section-15.1
var ip_addr = ip_regex.exec(candidate)[1]; console.debug(candidate)
const things = candidate.split(' ')
const ip_addr = things[4]
//remove duplicates //remove duplicates
if(ip_dups[ip_addr] === undefined) if(ip_dups[ip_addr] === undefined)
callback(ip_addr); callback(ip_addr);
@ -71,7 +73,6 @@
//listen for candidate events //listen for candidate events
pc.onicecandidate = function(ice){ pc.onicecandidate = function(ice){
//skip non-candidate events //skip non-candidate events
if(ice.candidate) if(ice.candidate)
handleCandidate(ice.candidate.candidate); handleCandidate(ice.candidate.candidate);
@ -88,7 +89,7 @@
}, function(){}); }, function(){});
//wait for a while to let everything done // wait for a while to let everything done
setTimeout(function(){ setTimeout(function(){
//read candidate info from local description //read candidate info from local description
var lines = pc.localDescription.sdp.split('\n'); var lines = pc.localDescription.sdp.split('\n');