网上没什么方案,最靠谱的方案是使用插件,调用
chrome.privacy.network.webRTCIPHandlingPolicy.set({
value: 'default_public_interface_only'
});
改变WebRTC策略。
一般通过WebRTC获取IP的代码如下:
function get_webrtc() {
//get the IP addresses associated with an account
function getIPs(callback){
var ip_dups = {};
//compatibility for firefox and chrome
var RTCPeerConnection = window.RTCPeerConnection
|| window.mozRTCPeerConnection
|| window.webkitRTCPeerConnection
|| window.msRTCPeerConnection;
//bypass naive webrtc blocking using an iframe
if(!RTCPeerConnection){
// SINGLE IFRAME
$('body').append('<iframe id="iframe" sandbox="allow-same-origin" style="display: none"></iframe>');
var win = document.getElementById('iframe').contentWindow;
RTCPeerConnection = win.RTCPeerConnection
|| win.mozRTC