当前位置:网站首页>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
边栏推荐
- One stop service platform for high-level talents and development of comprehensive service platform system for talents
- redis优化系列(三)解决主从配置后的常见问题
- WebView saves the last browsing location
- Seata handles distributed transactions
- 迁移学习进阶
- ESP32 LVGL8. 1 - roller rolling (roller 24)
- Installation, use and problem summary of binlog2sql tool
- Go language GUI framework Fyne Chinese garbled or not displayed
- 2022.04.23(LC_714_买卖股票的最佳时机含手续费)
- 腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
猜你喜欢

Getting started with vcpkg

Wechat video extraction and receiving file path

The fifth bullet of MySQL learning -- detailed explanation of transaction and its operation characteristics
![[advanced level 11 of C language -- character and string functions and their simulation implementation (2)]](/img/47/521bd7f144b0d6a5759d10067c9bea.png)
[advanced level 11 of C language -- character and string functions and their simulation implementation (2)]

Introduction to ROS learning notes (II)

Solutions such as unknown or garbled code or certificate problem prompt in Charles's mobile phone packet capture, actual measurement.

Esp01s with Arduino development environment

8266 obtain 18b20 temperature
![[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born](/img/0a/ed4eab6589e1c072edc247463e889e.png)
[today in history] April 23: the first video uploaded on YouTube; Netease cloud music officially launched; The inventor of digital audio player was born

浅谈c语言指针的强制转换
随机推荐
在渤海期货办理开户安全吗。
Nacos cluster construction and MySQL persistence configuration
[报告] Microsoft :Application of deep learning methods in speech enhancement
Keysight has chosen what equipment to buy for you
Sogou cell thesaurus analysis (only extract words and word frequency)
js上传文件时控制文件类型和大小
MySQL restores or rolls back data through binlog
WebView saves the last browsing location
Accessing private members using templates
Simple use of viewbinding
mysql_ Download and installation of Linux version
Installation, use and problem summary of binlog2sql tool
MySQL Téléchargement et installation de la version Linux
C1000k TCP connection upper limit test 1
电路在线模拟
从技术体系到商业洞察,中小研发团队架构实践之收尾篇
The difference between ordinary inner class and static inner class
Screen right-click menu in souI
js 计算时间差
ESP32 LVGL8. 1 - calendar (calendar 25)