当前位置:网站首页>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
- Introduction to ROS learning notes (II)
- One stop service platform for high-level talents and development of comprehensive service platform system for talents
- 2022.04.23(LC_714_买卖股票的最佳时机含手续费)
- 高层次人才一站式服务平台开发 人才综合服务平台系统
- Switching power supply design sharing and power supply design skills diagram
- Esp01s with Arduino development environment
- Nacos作为服务注册中心
- An 8266 crash
- js 计算时间差
猜你喜欢
7、 DOM (Part 2) - chapter after class exercises and answers
ESP32 LVGL8. 1 - textarea text area (textarea 26)
12 examples to consolidate promise Foundation
MySQL restores or rolls back data through binlog
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Installation, use and problem summary of binlog2sql tool
8266 obtain 18b20 temperature
Esp32 (UART 485 communication) - 485 communication of serial port (3)
该买什么设备,Keysight 给你挑好了
Raspberry pie 18b20 temperature
随机推荐
Using 8266 as serial port debugging tool
C1000k TCP connection upper limit test 1
Druid SQL和Security在美团点评的实践
About the operation of unit file reading (I)
为何PostgreSQL即将超越SQL Server?
电路在线模拟
ArcMap连接 arcgis server
openlayers 5.0 离散聚合点
The type initializer for ‘Gdip‘ threw an exception
中金财富怎么样?在上边开户安全吗
#yyds干货盘点#stringprep --- 因特网字符串预备
redis优化系列(三)解决主从配置后的常见问题
Openharmony open source developer growth plan, looking for new open source forces that change the world!
ESP32 LVGL8. 1 - textarea text area (textarea 26)
[记录]TypeError: this.getOptions is not a function
Xlslib use
ESP32 LVGL8. 1 - bar progress bar (bar 21)
C: generic reflection
ESP32 LVGL8. 1 - roller rolling (roller 24)
js 计算时间差