Last active
September 8, 2022 06:26
-
-
Save Mr-xn/a36a7703a9727f1f1c257d6e33c18055 to your computer and use it in GitHub Desktop.
WebRTC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<title>Get Real IP</title> | |
</head> | |
<h3>你的代理IP是:<div id=1></div></h3> | |
<h3>你的真实IP是:<div id=2></div></h3> | |
<script> | |
// turn 配置 | |
const config = { | |
iceServers: [{ | |
urls: "stun:stun.l.google.com:19302" // stun.voippro.com stun.voipraider.com 这里使用谷歌,线上部署直接替换 | |
}] | |
}; | |
// 构建 | |
let pc = new RTCPeerConnection(config); | |
pc.onicecandidate = function(event) { | |
if(event.candidate) | |
handleCandidate(event.candidate.candidate); | |
} | |
function handleCandidate(candidate) { | |
if (candidate.indexOf("srflx") != -1) { | |
console.log(candidate) | |
var regex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/ | |
var ip_addr = regex.exec(candidate)[0]; | |
//alert("Your public network ip: "+ ip_addr) | |
document.getElementById('2').innerHTML = ip_addr; | |
} | |
} | |
pc.createDataChannel(""); | |
pc.createOffer(function(result){ | |
pc.setLocalDescription(result); | |
}, function(){}); | |
</script> | |
// 也可 http://icanhazip.com/ | |
<script src='http://pv.sohu.com/cityjson?ie=utf-8'></script> | |
<script> | |
var ip=returnCitySN["cip"]; | |
//var city=returnCitySN["cname"]; | |
document.getElementById('1').innerHTML = ip; | |
</script> | |
<body> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
可以通过插件禁用 WebRTC 即可防止泄露