当前位置:网站首页>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
边栏推荐
- MySQL Téléchargement et installation de la version Linux
- [record] typeerror: this getOptions is not a function
- Using bafayun to control the computer
- Transaction processing of SQL Server database
- ArcMap连接 arcgis server
- Is it safe to open an account in Bohai futures.
- 2022.04.23 (the best time for lc_714_to buy and sell stocks, including handling charges)
- Minesweeping II of souI instance
- mysql_ Download and installation of Linux version
- Accessing private members using templates
猜你喜欢
Redis optimization series (III) solve common problems after master-slave configuration
Openharmony open source developer growth plan, looking for new open source forces that change the world!
Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.
Practice of Druid SQL and security in meituan review
Introduction to micro build low code zero Foundation (lesson 3)
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
MySQL restores or rolls back data through binlog
Esp32 (UART receiving and sending) - receiving and sending communication of serial port (4)
Getting started with vcpkg
mysql_ Download and installation of Linux version
随机推荐
Use of kotlin collaboration in the project
How about CICC wealth? Is it safe to open an account up there
Openharmony open source developer growth plan, looking for new open source forces that change the world!
Esp32 (UART 485 communication) - 485 communication of serial port (3)
Using Visual Studio code to develop Arduino
Advanced transfer learning
12个例子夯实promise基础
Codeforces Round #784 (Div. 4)
Esp32 drive encoder -- siq-02fvs3 (vscade + IDF)
Some records used by VS2010
Sogou cell thesaurus analysis (only extract words and word frequency)
Modify the font size of hint in editext
高层次人才一站式服务平台开发 人才综合服务平台系统
7、 DOM (Part 2) - chapter after class exercises and answers
Accessing private members using templates
mysql通过binlog恢复或回滚数据
openlayers 5.0 当地图容器大小改变时,重新加载地图
Treatment of incomplete display of listview height
中金财富怎么样?在上边开户安全吗
openlayers 5.0 热力图