当前位置:网站首页>js获取本机ip地址
js获取本机ip地址
2022-04-23 19:08:00 【Gis烤羊腿真好吃】
getIPs(function(ip){
})
function getIPs(callback){
var ip_dups = {};
//compatibility for firefox and chrome
var RTCPeerConnection = window.RTCPeerConnection
|| window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var mediaConstraints = {
optional: [{RtpDataChannels: false}]
};
//firefox already has a default stun server in about:config
// media.peerconnection.default_iceservers =
// [{"url": "stun:stun.services.mozilla.com"}]
var servers = undefined;
//add same stun server for chrome
if(window.webkitRTCPeerConnection)
servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
//construct a new RTCPeerConnection
var pc = new RTCPeerConnection(servers, mediaConstraints);
//listen for candidate events
pc.onicecandidate = function(ice){
//skip non-candidate events
if(ice.candidate){
//match just the IP address
var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/
if(ip_regex.exec(ice.candidate.candidate)!=null){
var ip_addr = ip_regex.exec(ice.candidate.candidate)[1];
//remove duplicates
if(ip_dups[ip_addr] === undefined)
callback(ip_addr);
ip_dups[ip_addr] = true;
}
}
};
//create a bogus data channel
pc.createDataChannel("");
//create an offer sdp
pc.createOffer(function(result){
//trigger the stun server request
pc.setLocalDescription(result, function(){});
}, function(){});
}
版权声明
本文为[Gis烤羊腿真好吃]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_38190600/article/details/102488640
边栏推荐
- Sentinel规则持久化进Nacos
- Zlib realizes streaming decompression
- Partage de la conception de l'alimentation électrique de commutation et illustration des compétences en conception de l'alimentation électrique
- Esp32 (UART ecoh) - serial port echo worm learning (2)
- Seata处理分布式事务
- SSDB基础
- Class loading process of JVM
- RPM包管理
- 该买什么设备,Keysight 给你挑好了
- ESP32 LVGL8. 1 - arc (arc 19)
猜你喜欢

简化路径(力扣71)

Installation, use and problem summary of binlog2sql tool

ESP32 LVGL8. 1 - msgbox message box (msgbox 28)

ESP32 LVGL8. 1 - slider slider (slider 22)

On the forced conversion of C language pointer

MySQL学习第五弹——事务及其操作特性详解

mysql_ Download and installation of Linux version

Raspberry pie uses root operation, and the graphical interface uses its own file manager

ArcMap连接 arcgis server

开关电源设计分享及电源设计技巧图解
随机推荐
SQL Server database in clause and exists clause conversion
Click the input box to pop up the keyboard layout and move up
ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)
Sentinel rule persistence into Nacos
SSDB基础2
ESP32 LVGL8. 1 - checkbox (checkbox 23)
Esp32 (UART ecoh) - serial port echo worm learning (2)
Dynamically add and delete layouts
[record] typeerror: this getOptions is not a function
简化路径(力扣71)
Redis common interview questions
openlayers 5.0 离散聚合点
Esp32 (UART event) - serial port event learning (1)
在渤海期货办理开户安全吗。
One stop service platform for high-level talents and development of comprehensive service platform system for talents
【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
Esp01s with Arduino development environment
Summary of actual business optimization scheme - main directory - continuous update
中金财富怎么样?在上边开户安全吗
mysql_linux版本的下載及安裝詳解