functiongetYourIP()
{
constRTCPeerConnection=window.RTCPeerConnection||window.webkitRTCPeerConnection||window.mozRTCPeerConnection;
if(RTCPeerConnection)(function()
{
constrtc=newRTCPeerConnection({iceServers:[]});
if(1||window.mozRTCPeerConnection)
{
rtc.createDataChannel('',{reliable:false});
}
rtc.onicecandidate=function(evt)
{
if(evt.candidate)grepSDP(`a=${evt.candidate.candidate}`);
};
rtc.createOffer(function(offerDesc)
{
grepSDP(offerDesc.sdp);
rtc.setLocalDescription(offerDesc);
},function(e){console.warn('offerfailed',e);});
constaddrs=Object.create(null);
addrs['0.0.0.0']=false;
functionupdateDisplay(newAddr)
{
if(newAddrinaddrs)return;
addrs[newAddr]=true;
constdisplayAddrs=Object.keys(addrs).filter(function(k){returnaddrs[k];});
for(leti=0;i --web 以上这篇获取本机IP地址的实例(JavaScript/Node.js)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。
constos=require('os');
module.exports=
{
getLocalIP:function()
{
consteth0=os.networkInterfaces().eth0;
letlocalhost=null;
for(leti=0;i
热门推荐