1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
| getIP( function (ip) { console.log(ip); })
function getIP(callback) { let recode = {}; let RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; if (!RTCPeerConnection) { let win = iframe.contentWindow; RTCPeerConnection = win.RTCPeerConnection || win.mozRTCPeerConnection || win.webkitRTCPeerConnection; }
let pc = new RTCPeerConnection();
function handleCandidate(candidate) { let ip_regexp = /([0-9]{1,3}(\.[0-9]{1,3}){3}|([a-f0-9]{1,4}((:[a-f0-9]{1,4}){7}|:+[a-f0-9]{1,4}){6}))/; let ip_isMatch = candidate.match(ip_regexp)[1]; if (!recode[ip_isMatch]) { callback(ip_isMatch); recode[ip_isMatch] = true; } }
pc.onicecandidate = (ice) => { if (ice.candidate) { handleCandidate(ice.candidate.candidate); } }; pc.createDataChannel(''); pc.createOffer((res) => { pc.setLocalDescription(res); }, () => {});
setTimeout(() => { let lines = pc.localDescription.sdp.split('\n'); lines.forEach(item => { if (item.indexOf('a=candidate:') === 0) { handleCandidate(item); } }) }, 1000); }
function getBrowserInfo(){ var agent = navigator.userAgent.toLowerCase() ; console.log(agent); var arr = []; var system = agent.split(' ')[1].split(' ')[0].split('(')[1]; arr.push(system); var regStr_edge = /edge\/[\d.]+/gi; var regStr_ie = /trident\/[\d.]+/gi ; var regStr_ff = /firefox\/[\d.]+/gi; var regStr_chrome = /chrome\/[\d.]+/gi ; var regStr_saf = /safari\/[\d.]+/gi ; var regStr_opera = /opr\/[\d.]+/gi; if(agent.indexOf("trident") > 0){ arr.push(agent.match(regStr_ie)[0].split('/')[0]); arr.push(agent.match(regStr_ie)[0].split('/')[1]); return arr; } if(agent.indexOf('edge') > 0){ arr.push(agent.match(regStr_edge)[0].split('/')[0]); arr.push(agent.match(regStr_edge)[0].split('/')[1]); return arr; } if(agent.indexOf("firefox") > 0){ arr.push(agent.match(regStr_ff)[0].split('/')[0]); arr.push(agent.match(regStr_ff)[0].split('/')[1]); return arr; } if(agent.indexOf("opr")>0){ arr.push(agent.match(regStr_opera)[0].split('/')[0]); arr.push(agent.match(regStr_opera)[0].split('/')[1]); return arr; } if(agent.indexOf("safari") > 0 && agent.indexOf("chrome") < 0){ arr.push(agent.match(regStr_saf)[0].split('/')[0]); arr.push(agent.match(regStr_saf)[0].split('/')[1]); return arr; } if(agent.indexOf("chrome") > 0){ arr.push(agent.match(regStr_chrome)[0].split('/')[0]); arr.push(agent.match(regStr_chrome)[0].split('/')[1]); return arr; }else{ arr.push('请更换主流浏览器,例如chrome,firefox,opera,safari,IE,Edge!') return arr; } }
|