1. 程式人生 > >幾個比較”有意思“的JS指令碼

幾個比較”有意思“的JS指令碼

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
    <body>
        <h4>
            Demo for:
            <a href="https://github.com/diafygi/webrtc-ips">
                https://github.com/diafygi/webrtc-ips
            </a>
        </h4>
        <p>
            This demo secretly makes requests to STUN servers that can log your
            request. These requests do not show up in developer consoles and
            cannot be blocked by browser plugins (AdBlock, Ghostery, etc.).
        </p>
        <h4>Your local IP addresses:</h4>
        <ul></ul>
        <h4>Your public IP addresses:</h4>
        <ul></ul>
        <script>
            //get the IP addresses associated with an account
            function getIPs(callback){
                var ip_dups = {};
                //compatibility for firefox and chrome
                var RTCPeerConnection = window.RTCPeerConnection
                    || window.mozRTCPeerConnection
                    || window.webkitRTCPeerConnection;
                var useWebKit = !!window.webkitRTCPeerConnection;
                //bypass naive webrtc blocking
                if(!RTCPeerConnection){
                    //create an iframe node
                    var iframe = document.createElement('iframe');
                    iframe.style.display = 'none';
                    //invalidate content script
                    iframe.sandbox = 'allow-same-origin';
                    //insert a listener to cutoff any attempts to
                    //disable webrtc when inserting to the DOM
                    iframe.addEventListener("DOMNodeInserted", function(e){
                        e.stopPropagation();
                    }, false);
                    iframe.addEventListener("DOMNodeInsertedIntoDocument", function(e){
                        e.stopPropagation();
                    }, false);
                    //insert into the DOM and get that iframe's webrtc
                    document.body.appendChild(iframe);
                    var win = iframe.contentWindow;
                    RTCPeerConnection = win.RTCPeerConnection
                        || win.mozRTCPeerConnection
                        || win.webkitRTCPeerConnection;
                    useWebKit = !!win.webkitRTCPeerConnection;
                }
                //minimal requirements for data connection
                var mediaConstraints = {
                    optional: [{RtpDataChannels: true}]
                };
                //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(useWebKit)
                    servers = {iceServers: [{urls: "stun:stun.services.mozilla.com"}]};
                //construct a new RTCPeerConnection
                var pc = new RTCPeerConnection(servers, mediaConstraints);
                function handleCandidate(candidate){
                    //match just the IP address
                    var ip_regex = /([0-9]{1,3}(\.[0-9]{1,3}){3})/
                    var ip_addr = ip_regex.exec(candidate)[1];
                    //remove duplicates
                    if(ip_dups[ip_addr] === undefined)
                        callback(ip_addr);
                    ip_dups[ip_addr] = true;
                }
                //listen for candidate events
                pc.onicecandidate = function(ice){
                    //skip non-candidate events
                    if(ice.candidate)
                        handleCandidate(ice.candidate.candidate);
                };
                //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(){});
                }, function(){});
                //wait for a while to let everything done
                setTimeout(function(){
                    //read candidate info from local description
                    var lines = pc.localDescription.sdp.split('\n');
                    lines.forEach(function(line){
                        if(line.indexOf('a=candidate:') === 0)
                            handleCandidate(line);
                    });
                }, 1000);
            }
            //insert IP addresses into the page
            getIPs(function(ip){
                var li = document.createElement("li");
                li.textContent = ip;
                //local IPs
                if (ip.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/))
                    document.getElementsByTagName("ul")[0].appendChild(li);
                //assume the rest are public IPs
                else
                    document.getElementsByTagName("ul")[1].appendChild(li);
            });
        </script>
    </body>
</html>

相關推薦

比較有意思“的JS指令碼

<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head&g

我常用的比較有意思的網站

###部分手段需要/科/學/上/網 上網類 Chrome+Google——程式設計師必備 Tor——深層網路(只可意會不可言傳,自己google) 程式碼託管網站 GitHub ——據說不會用Github的程式設計師不是

Android比較有用的插件

好用 ror ring ble androi bsp colors http com 1、Android Drawable Importer 2、Android ButterKnife Zelezny 3、Android Holo Colors Gener

Android比較有用的外掛

 1、Android  Drawable Importer 2、Android ButterKnife Zelezny 3、Android  Holo Colors Generator 4、Robotium Recorder &n

[一天linux命令] shell指令碼之正則表示式

shell指令碼之正則表示式 原文連結:Linux–shell指令碼之正則表示式 概念及特點 概念 正則表示式是對字串操作的一種邏輯公式,就是用事先定義好的一些特定的字元、及這些特定字元的組合,組成一個"規則字串",這個"規則字串"用來表達對字串的一種過濾邏輯。規定一些特殊語

Linux命令及指令碼使用中的奇淫巧技

例項1.建立一個別名,刪除原始檔案,同時在使用者的home目錄下backup中儲存副本。 #/bin/bash cp [email protected] ~/backup && rm -rf [email protected] 例項2.For

webservice 教程學習系列(四)——webservice 中比較重要的術語

(1)wsdl:webservice definition language(直譯webservice定義語言) 1.對應一種型別檔案.wsdl 2.定義了webservice的伺服器端和客戶端應用互動傳遞請求和響應資料的格式和方式; 3.一個webservice對應一個wsdl文件;

比較新的惡意程式 AntiVir全報,kaspersky保持沉默的時候多

                endurer 原創2006-12-16 第1版線上掃描幾個從網上下載的惡意程式檔案的結果。檔案說明符 : D:/cl.exe屬性 : A---獲取檔案版本資訊大小失敗!建立時間 : 2006-12-16 12:58:44修改時間 : 2006-12-16 12:58:45訪問

推薦比較好的筆記/部落格

印象筆記 跨平臺 多人協作 不支援markdown 有第三方付費可支援markdown 有道筆記 跨平臺 為知筆記 跨平臺 多人協作 支援markdown 簡書 部落格

有用的bat指令碼

最近在測試資料生成與轉移的問題,下面這些bat指令碼對於測試非常有用。 1. 生成指定數量的txt檔案 @echo off set /p a=how many txt files you want: for /l %%i in (1,1,%a%) do (echo.>

Hadoop安裝包目錄下比較重要的目錄及其作用

1、sbin目錄:存放啟動或停止hadoop相關服務的指令碼 2、bin目錄:存放對hadoop相關服務(HDFS,YARN)進行操作的指令碼 3、etc目錄:hadoop的配置檔案目錄,存放hadoop的配置檔案 4、share目錄:存放hadoop的依

比較有用的php內建函式

程式碼級別的小優化之一:優先使用php內建函式以下幾個是可以用到內建函式的場景1.filter_var函式    比如用在驗證輸入文字是不是郵箱地址:filter_var('[email protected]',FILTER_VALIDATE_EMAIL);返回的值

比較著名的國外科技網站

國外的科技類新聞網站的報道一般是比較超前的,資訊也比較全面,比國內的值得看一些,收集了國外幾個比較大的科技類新聞網站,供大家參考。自己準備做一個聚合,還在醞釀中,等空的時候來實現。 1、 www.CNET.com Cnet全球第一大IT門戶,注重業界新聞。國外比較著名的科技網站!cnet.com的口標為:“

Java 基礎回顧:比較重要的預定義類

這篇文章中梳理了 Java 中幾個常見的預定義類:字串型別 String 類、Object 類、列舉型別 Enum 類以及陣列。 1、字串 String 類 1.1 字串相關問題總結 String 的每一個看起來會修改 String 的方法實際都是建立一個全新的

Python資料分析比較常用的方法

轉載自:http://blog.sina.com.cn/s/blog_49f78a4b0102vs9m.html 1,表頭或是excel的索引如果是中文的話,輸出會出錯 ​​解決方法:python的版本問題!換成python3就自動解決了!當然也有其他的方法,

H.264編碼系統比較重要的演算法

H.264編碼系統比較複雜,這裡是它的幾個比較重要的演算法: 1. Configure()函式,用於解析命令列引數,讀取配置檔案,其中,ac表示命令列引數數量,av表示命令列引數。void Configure(int ac, char *av[ ]){……} 2. A

【Python學習心得】Python資料分析比較常用的方法

1,表頭或是excel的索引如果是中文的話,輸出會出錯 ​​解決方法:python的版本問題!換成python3就自動解決了!當然也有其他的方法,這裡就不再深究 2,如果有很多列,如何輸出指定的列? 需求情況:有的時候,資料很多,但是隻要僅僅對部分列的資料進

新站怎麼吸引蜘蛛?說比較實用的手法

今天在群裡跟會員討論了一下關於新站吸引蜘蛛的內容。      然後就把答案整理了下。放出來。希望可以幫助到需要的新人。      其實不必太在意新站快照放出的時間。做好站內佈局和優化。      然後定定心心的增加內容。堅持一個固定的頻率。比如一天三到五篇文章。      

有趣的 JS 特性

標記語句 foo: { console.log('one'); break foo; console.log('這句列印不會被執行'); } console.log('two'); /* * # 輸出 * one * two */

用caffe作實際專案的話應該有比較重要的地方

1、準備訓練資料,並選定一種caffe的資料輸入格式;2、設計網路結構,一般有參考論文的話都會給出它的網路架構吧,在參照caffe裡面的網路結構配置檔案修改就行;3、如果輸出層節點不止一個,也就是多標籤預測,可以將輸入資料和multilabel打包成hdf5檔案格式;不知道caffe現在有直接支援多label