当前位置:网站首页>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
边栏推荐
- Circuit on-line simulation
- 网络协议之:sctp流控制传输协议
- ESP32 LVGL8. 1 - bar progress bar (bar 21)
- Screenshot using projectmediamanager
- 高层次人才一站式服务平台开发 人才综合服务平台系统
- SQL常用的命令
- Installation, use and problem summary of binlog2sql tool
- [record] typeerror: this getOptions is not a function
- mysql_linux版本的下載及安裝詳解
- [报告] Microsoft :Application of deep learning methods in speech enhancement
猜你喜欢

Practice of Druid SQL and security in meituan review

Network protocol: SCTP flow control transmission protocol

Client interns of a large factory share their experience face to face

【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生

Esp01s with Arduino development environment

Using Visual Studio code to develop Arduino

JVM的类加载过程

浅谈c语言指针的强制转换

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

ESP32 LVGL8. 1 - roller rolling (roller 24)
随机推荐
mysql_linux版本的下載及安裝詳解
【历史上的今天】4 月 23 日:YouTube 上传第一个视频;网易云音乐正式上线;数字音频播放器的发明者出生
From technical system to business insight, the closing chapter of the practice of small and medium-sized R & D team structure
ESP32 LVGL8. 1 - calendar (calendar 25)
I just want to leave a note for myself
Client interns of a large factory share their experience face to face
Esp32 (UART ecoh) - serial port echo worm learning (2)
Switching power supply design sharing and power supply design skills diagram
Go 语言 GUI 框架 fyne 中文乱码或者不显示的问题
腾讯云GPU最佳实践-使用jupyter pycharm远程开发训练
Getting started with vcpkg
Practice of Druid SQL and security in meituan review
Simple use of viewbinding
Fundamentals of machine learning theory -- some terms about machine learning
SSDB foundation 3
openlayers 5.0 加载arcgis server 切片服务
2022.04.23(LC_763_划分字母区间)
Esp32 (UART 485 communication) - 485 communication of serial port (3)
Xlslib use
迁移学习进阶