一段代码检查你的浏览器IP泄露(WebRTC老话题了)
# 简介老话题来水一手哈哈,原理很简单,就是浏览器的WebRTC功能可能导致你的ip泄露,很可能不走你的浏览器代理,快来检测一下吧~
# 代码
直接复制这段代码到你的F12控制台执行,如果有ip输出说明你的ip可能存在泄露的情况~
```javascript
(function() {
// WebRTC IPs
const iceServers = [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
{ urls: 'stun:stun2.l.google.com:19302' },
{ urls: 'stun:stun3.l.google.com:19302' },
{ urls: 'stun:stun4.l.google.com:19302' },
];
function getUserIPs(callback) {
const myPeerConnection = new RTCPeerConnection({ iceServers });
myPeerConnection.createDataChannel("");
myPeerConnection.createOffer().then(offer => myPeerConnection.setLocalDescription(offer));
myPeerConnection.onicecandidate = function(event) {
if (event.candidate) {
const parts = event.candidate.candidate.split(' ');
const ip = parts;
callback(ip);
}
};
}
getUserIPs((ip) => {
const ipv4Regex = /^(25|2|??)\.(25|2|??)\.(25|2|??)\.(25|2|??)$/;
const ipv6Regex = /^(({1,4}:){7,7}{1,4}|({1,4}:){1,7}:|({1,4}:){1,6}:{1,4}|({1,4}:){1,5}(:{1,4}){1,2}|({1,4}:){1,4}(:{1,4}){1,3}|({1,4}:){1,3}(:{1,4}){1,4}|({1,4}:){1,2}(:{1,4}){1,5}|{1,4}:((:{1,4}){1,6})|:((:{1,4}){1,7}|:)|fe80:(:{0,4}){0,4}%{1,}|::(ffff(:0{1,4}){0,1}:){0,1}(({1,4}:){1,4}|((25|(2|1{0,1}){0,1})\.){3,3}(25|(2|1{0,1}){0,1}))|({1,4}:){1,4}:((25|(2|1{0,1}){0,1})\.){3,3}(25|(2|1{0,1}){0,1}))$/;
if (ipv4Regex.test(ip)) {
console.log('WebRTC IPv4 Address:', ip);
} else if (ipv6Regex.test(ip)) {
console.log('WebRTC IPv6 Address:', ip);
} else {
console.log('WebRTC Local IP Address:', ip);
}
});
})();
```
# 修复建议
如果存在ip泄露的情况推荐安装一个插件阻止泄露,例如Chrome自己的(https://chromewebstore.google.com/detail/webrtc-network-limiter/npeicpdbkakmehahjeeohfdhnlpdklia) 直接装个chrome插件禁掉就好了
https://chromewebstore.google.com/detail/webrtc-control/fjkmabmdepjfammlpliljpnbhleegehm?hl=zh-CN VM1399:12 Uncaught TypeError: RTCPeerConnection is not a constructor
at getUserIPs (<anonymous>:12:34)
at <anonymous>:25:5
at <anonymous>:36:11
页:
[1]