
























这是一个创建于 4525 天前的主题,其中的信息可能已经有所发展或是发生改变。
可以直接从本地读取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。然后一个异步请求,就可以被服务端提取。浏览器无任何安全提示。
第 1 条附言 · 2014 年 1 月 24 日
1 ihacku 2014 年 1 月 23 日chrome://flags/ 试试关掉里面相关的flag试试? |
2 notedit 2014 年 1 月 23 日webrtc 启用的时候都要被授权 你可以点击deny |
3 the13matrix 2014 年 1 月 23 日@ihacku 里面有停用webrtc,但显示:抱歉,此实验无法在您的平台上进行。 |
5 airyland 2014 年 1 月 23 日感谢楼主分享,亲测有效。原来可以这样获取。。 |
6 initialdp 2014 年 1 月 23 日 via iPad不奇怪啊,webrtc本来就是用于通信的,肯定需要拿到这些地址信息才行。 |
7 switch 2014 年 1 月 23 日可以使用 GM 来重写 RTCPeerConnection 构造函数,使其失效。 |
8 est 2014 年 1 月 23 日chrome还有个bug就是可以后台麦克风录音 |
9 xvfeng 2014 年 1 月 23 日webrtc本身没有连接功能.需要先通过一个signal的服务器来建立连接才行. 正常情况下根本不可能出现安全问题. 楼主禁用webrtc是要怎样... |
11 yfdyh000 2014 年 1 月 24 日确认是不经授权的泄露。 |
12 582033 2014 年 1 月 24 日@the13matrix 这不算什么吧,相比chrome的另一大功能(话筒处于随时监听状态)小巫见大巫了啊。 |
14 DearMark 2014 年 1 月 24 日我的firefox无法获取ip,chrome可以 |
15 bigbee 2014 年 8 月 11 日我的firefox、chrome都可以 |
17 impig33 2016 年 5 月 13 日来个详细的说明 |
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。