浏览器输入:
edge://flags/#enable-webrtc-hide-local-ips-with-mdns
Anonymize local IPs exposed by WebRTC 状态改为disable
JS方法:
function f() {
if(typeof window != 'undefined'){
var RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var rtc = new RTCPeerConnection()
rtc.createDataChannel('');
rtc.createOffer( offerDesc => {
rtc.setLocalDescription(offerDesc)
}, e => { console.log(e)})
rtc.onicecandidate =(evt) => {
if (evt.candidate) {
console.log('evt:',evt.candidate)
let ip_rule = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
var ip_addr = ip_rule.exec(evt.candidate.candidate)[1]
console.log('ip_addr:',ip_addr)
}}
}文章来源:https://www.toymoban.com/news/detail-430850.html
}文章来源地址https://www.toymoban.com/news/detail-430850.html
到了这里,关于浏览器获取本地IP地址(不是浏览器的url地址的ip)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!