怎样禁用浏览器的WebRTC

如题所述

可以直接从本地读取IP。和ipconfig /all看到的IP一样。
如果电脑直接播号上网,则获取到的就是公网IP。如果是家庭、学校、公司的内网,获取到的就是内网IP。如果系统里有虚拟网卡,虚拟网卡IP也加入列表。
测试代码:(对Chrome和Firefox有效)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获取内网IP</title>
</head>
<body>
您的内网IP:
<span id="list"></span>
<script>
// NOTE: window.RTCPeerConnection is "not a constructor" in FF22/23
var RTCPeerConnection = /*window.RTCPeerConnection ||*/ window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
if (RTCPeerConnection) (function () {
var rtc = new RTCPeerConnection({iceServers:[]});
if (window.mozRTCPeerConnection) { // FF needs a channel/stream to proceed
rtc.createDataChannel('', {reliable:false});
};
rtc.onicecandidate = function (evt) {
if (evt.candidate) grepSDP(evt.candidate.candidate);
};
rtc.createOffer(function (offerDesc) {
grepSDP(offerDesc.sdp);
rtc.setLocalDescription(offerDesc);
}, function (e) { console.warn("offer failed", e); });
var addrs = Object.create(null);
addrs["0.0.0.0"] = false;
function updateDisplay(newAddr) {
if (newAddr in addrs) return;
else addrs[newAddr] = true;
var displayAddrs = Object.keys(addrs).filter(function (k) { return addrs[k]; });
document.getElementById('list').innerHTML = displayAddrs.join(" or perhaps ") || "n/a";
}
function grepSDP(sdp) {
var hosts = [];
sdp.split('\r\n').forEach(function (line) { // c.f.http://tools.ietf.org/html/rfc4566#page-39
if (~line.indexOf("a=candidate")) { //http://tools.ietf.org/html/rfc4566#section-5.13
var parts = line.split(' '), //http://tools.ietf.org/html/rfc5245#section-15.1
addr = parts[4],
type = parts[7];
if (type === 'host') updateDisplay(addr);
} else if (~line.indexOf("c=")) { //http://tools.ietf.org/html/rfc4566#section-5.7
var parts = line.split(' '),
addr = parts[2];
updateDisplay(addr);
}
});
}
})(); else {
document.getElementById('list').innerHTML = "<code>ifconfig | grep inet | grep -v inet6 | cut -d\" \" -f2 | tail -n1</code>";
document.getElementById('list').nextSibling.textContent = "In Chrome and Firefox your IP should display automatically, by the power of WebRTCskull.";
}
</script>
</body>
</html>
建网站的朋友,可以用这个判断访客是内网用户还是公网。并且获取访客内网IP。
不管你用了多少层匿名代理/VPN,这段代码都能直接提取本地IP。然后一个异步请求,就可以被服务端提取。浏览器无任何安全提示。
温馨提示:答案为网友推荐,仅供参考
相似回答