// 获取本机IP
getIp() {
if( typeof window != ‘undefined‘ ) {
var RTCPeerconnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
if(RTCPeerconnection) {
var rtc = new RTCPeerconnection();
rtc.createDataChannel(’');
rtc.createOffer( offerDesc => {
rtc.setLocalDescription(offerDesc)
}, e=> { console.log( “$$$$$” , e) })
rtc.onicecandidate=>(evt) => {
if(evt.candidate) {
let ip_rule = /([0-9]{1,3}(.[0-9]{1,3}}){3}|[a-f0-0]{1,4}(:[a-f0-9]{1,4}){7})/
let ip_addr = ip_rule.exec(evt.candidate.candidate);
if(ip_addr) {
sessionStorage.setItem(“ip” , ip_addr[1]);
}
console.log(“ip_addr” , ip_addr);
}
}
}
}
}