現在のIPアドレスを取得するには、ブラウザ

関数findIP(コールバック){
     VAR myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection; // Firefoxとクロムの互換
    // はconsole.log(myPeerConnection)

    VAR restartConfig = {iceServers:[]}。
    // VARのPC =新しいmyPeerConnection({iceServers:[]})、
    VaRの PC = 新しいmyPeerConnection({iceServers:[]})、
        NOOP = 関数(){}、
        localIPs = {}、
        ipRegex = /([0- 9] {1,3}(\ [0-9] {1,3}){3} | [-f0-9] {1,4}([-f0-9] {1,4 }){7})/ gで、
        キー; 

    関数ipIterate(IP){
         場合(!localIPs [IP])コールバック(IP)。
        localIPs [IP] = ; 
    } 
    pc.setConfiguration(restartConfig)。
    pc.createDataChannel( "" ); 
    。pc.createOffer()は(関数(SDP){ 
        sdp.sdp.split( '\ n')のforEach(関数(線){
             場合(line.indexOf( '候補')<0)のリターン; 
            line.match (ipRegex).forEach(ipIterate); 
        }); 
        pc.setLocalDescription(SDP、NOOP、NOOP); 
    }); 
    pc.onicecandidate = 機能(氷){
         場合(アイス|| || ice.candidate ice.candidate.candidate || ice.candidate.candidate.match(ipRegex)!!!!)リターン
        ice.candidate.candidate.match(ipRegex).forEach(ipIterate)。
    }。
} 

findIP(関数(IP){ 
    にconsole.log( 'IP得た:' 、IP); 
});

 

 

一部のブラウザが出ることができない場合は、削除上記のコードは、Ctrl +シフト+の実装にキャッシュをクリアしようとします

 

おすすめ

転載: www.cnblogs.com/myloveblogs/p/11817097.html