谷歌:
在浏览器导航栏输入:chrome://flags/
然后找到:Anonymize local IPs exposed by WebRTC 设置为 Disabled
Edge
-
浏览器输入: edge://flags/#enable-webrtc-hide-local-ips-with-mdns
-
把 Anonymize local IPs exposed by WebRTC 设置为 disabled ( 刷新程序,IP正常显示 )
然后在代码中获取当前ip。
const getMyId = () => {
window.RTCPeerConnection = window.RTCPeerConnection
var pc = new RTCPeerConnection({ iceServers: [] }), noop = function () { };
pc.createDataChannel(''); //create a bogus data channel
pc.createOffer(pc.setLocalDescription.bind(pc), noop); // create offer andsetlocaldescription
pc.onicecandidate = function (ice) {
if (ice && ice.candidate && ice.candidate.candidate) {
var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)![1]
console.log('my IP: ', myIP);
getRTSP(myIP)
pc.onicecandidate = noop; 10
}
};
}