当前位置:网站首页>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
边栏推荐
- openlayers 5.0 离散聚合点
- Yyds dry goods inventory stringprep --- Internet string preparation
- Disable Ctrl + Alt + Del
- The type initializer for ‘Gdip‘ threw an exception
- Treatment of incomplete display of listview height
- [record] typeerror: this getOptions is not a function
- Client interns of a large factory share their experience face to face
- Sentinel rule persistence into Nacos
- Screen right-click menu in souI
- ESP32 LVGL8. 1 - img picture (IMG 20)
猜你喜欢

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

OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!

FTP、ssh远程访问及控制
![[报告] Microsoft :Application of deep learning methods in speech enhancement](/img/29/2d2addd826359fdb0920e06ebedd29.png)
[报告] Microsoft :Application of deep learning methods in speech enhancement

mysql_linux版本的下載及安裝詳解

Summary of actual business optimization scheme - main directory - continuous update

Esp32 (UART 485 communication) - 485 communication of serial port (3)

8266 obtain 18b20 temperature

Wechat video extraction and receiving file path

Installation, use and problem summary of binlog2sql tool
随机推荐
迁移学习进阶
RPM package management
ESP32 LVGL8. 1 - bar progress bar (bar 21)
SSDB基础2
腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
Eight bit binary multiplier VHDL
Use of kotlin collaboration in the project
ESP32 LVGL8. 1 - msgbox message box (msgbox 28)
ESP32 LVGL8. 1 - input devices (input devices 18)
Sentinel服务熔断实战(sentinel整合ribbon+openFeign+fallback)
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
How can programmers quickly develop high-quality code?
MySQL Téléchargement et installation de la version Linux
WebView opens H5 video and displays gray background or black triangle button. Problem solved
Accessing private members using templates
Disable Ctrl + Alt + Del
Xlslib use
The difference between ordinary inner class and static inner class
Raspberry pie uses root operation, and the graphical interface uses its own file manager
【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生