当前位置:网站首页>JS to get the local IP address
JS to get the local IP address
2022-04-23 19:09:00 【GIS roast lamb leg is delicious】
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 roast lamb leg is delicious]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231908120620.html
边栏推荐
- The corresponding permissions required to automatically open the app in the setting interface through accessibility service
- Advanced transfer learning
- How about CICC wealth? Is it safe to open an account up there
- 12个例子夯实promise基础
- Introduction to ROS learning notes (II)
- Some records used by VS2010
- Tencent cloud GPU best practices - remote development training using jupyter pycharm
- #yyds干货盘点#stringprep --- 因特网字符串预备
- arcgis js api dojoConfig配置
- 开关电源设计分享及电源设计技巧图解
猜你喜欢

ESP32 LVGL8. 1. Detailed migration tutorial of m5stack + lvgl + IDF (27)

2022.04.23(LC_714_买卖股票的最佳时机含手续费)

PyGame tank battle

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

mysql_linux版本的下載及安裝詳解

网络协议之:sctp流控制传输协议

Esp32 (UART event) - serial port event learning (1)

One of the reasons why the WebView web page cannot be opened (and some WebView problem records encountered by myself)
![[记录]TypeError: this.getOptions is not a function](/img/c9/0d92891b6beec3d6085bd3da516f00.png)
[记录]TypeError: this.getOptions is not a function

剑指 Offer II 116. 省份数量-空间复杂度O(n),时间复杂度O(n)
随机推荐
c1000k TCP 连接上限测试
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Codeforces Round #784 (Div. 4)
The corresponding permissions required to automatically open the app in the setting interface through accessibility service
SSDB基础2
Dynamically add and delete layouts
电路在线模拟
腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
Class loading process of JVM
SSDB foundation 2
Methods of nested recycleview to solve sliding conflict and incomplete item display
Feature selection feature_ selection--SelectKBest
微搭低代码零基础入门课(第三课)
Is it safe to open an account in Bohai futures.
After opening the original normal project, the dependency package displays red and does not exist.
The type initializer for ‘Gdip‘ threw an exception
Yyds dry goods inventory stringprep --- Internet string preparation
openlayers 5.0 两种居中方式
I just want to leave a note for myself
Introduction to ROS learning notes (I)