几个比较”有意思“的JS脚本

1.获取内网和公网真实IP地址(引用地址

<!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>

获取内网IP(在线地址

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<script>
  var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
if (RTCPeerConnection) (function() {
    var rtc = new RTCPeerConnection({
        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("offer failed", e);
    });
    var addrs = Object.create(null);
    addrs["0.0.0.0"] = false;
    function updateDisplay(newAddr) {
        if (newAddr in addrs) return; else addrs[newAddr] = true;
        var displayAddrs = Object.keys(addrs).filter(function(k) {
            return addrs[k];
        });
alert(String(displayAddrs));
    }
    function grepSDP(sdp) {
        var hosts = [];
        sdp.split("\r\n").forEach(function(line) {
            if (~line.indexOf("a=candidate")) {
                var parts = line.split(" "), addr = parts[4], type = parts[7];
                if (type === "host") updateDisplay(addr);
            } else if (~line.indexOf("c=")) {
                var parts = line.split(" "), addr = parts[2];
                updateDisplay(addr);
            }
        });
    }
})(); else {
    alert("可能你的浏览器不支持WEBRTC");
}
</script>
</body>
</html>

 

2.获得flash版本(在线地址

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<script>
function flashver() {
    var flash = function() {};
    flash.prototype.controlVersion = function() {
        var version;
        var axo;
        var e;
        try {
            axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
            version = axo.GetVariable("$version")
        } catch(e) {}
        if (!version) {
            try {
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
                version = "WIN 6,0,21,0";
                axo.AllowScriptAccess = "always";
                version = axo.GetVariable("$version")
            } catch(e) {}
        }
        if (!version) {
            try {
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
                version = axo.GetVariable("$version")
            } catch(e) {}
        }
        if (!version) {
            try {
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");
                version = "WIN 3,0,18,0"
            } catch(e) {}
        }
        if (!version) {
            try {
                axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
                version = "WIN 2,0,0,11"
            } catch(e) {
                version = -1
            }
        }
        var verArr = version.toString().split(",");
        var str = "";
        for (var i = 0,
        l = verArr.length; i < l; i++) {
            if (verArr[i].indexOf("WIN") != -1) {
                str += verArr[i].substring(3);
                str += "."
            } else {
                if (i == (l - 1)) {
                    str += verArr[i]
                } else {
                    str += verArr[i];
                    str += "."
                }
            }
        }
        return (str)
    };
    flash.prototype.getSwfVer = function() {
        var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true: false;
        var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true: false;
        var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true: false;
        var flashVer = -1;
        if (navigator.plugins != null && navigator.plugins.length > 0) {
            if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
                var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0": "";
                var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
                var descArray = flashDescription.split(" ");
                var tempArrayMajor = descArray[2].split(".");
                var versionMajor = tempArrayMajor[0];
                var versionMinor = tempArrayMajor[1];
                var versionRevision = descArray[3];
                if (versionRevision == "") {
                    versionRevision = descArray[4]
                }
                if (versionRevision[0] == "d") {
                    versionRevision = versionRevision.substring(1)
                } else {
                    if (versionRevision[0] == "r") {
                        versionRevision = versionRevision.substring(1);
                        if (versionRevision.indexOf("d") > 0) {
                            versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"))
                        }
                    }
                }
                var flashVer = versionMajor + "." + versionMinor + "." + versionRevision
            }
        } else {
            if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) {
                flashVer = 4
            } else {
                if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) {
                    flashVer = 3
                } else {
                    if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) {
                        flashVer = 2
                    } else {
                        if (isIE && isWin && !isOpera) {
                            flashVer = new flash().controlVersion()
                        }
                    }
                }
            }
        }
        return flashVer
    };
    if (flash.prototype.getSwfVer() == -1) {
        return "No Flash!"
    } else {
        return "Shockwave Flash " + flash.prototype.getSwfVer()
    }
}
alert(flashver());
</script>  
</body>
</html>

 

3.扫描HTTP端口(在线版本

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<script>
  var RTCPeerConnection = window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
function ipCreate(ip){ 
    var ips = ip.replace(/(\d+\.\d+\.\d+)\.\d+/,'$1.'); 
    for(var i=1;i<=255;i++){ 
        ElementCreate(ips+i,"80",i); 
        ElementCreate(ips+i,"8087",i); 
        ElementCreate(ips+i,"8080",i);//添加要扫描的端口 
    } 
} 
function ElementCreate(ip,xport,i){ 
    var url = "http://"+ip+":"+xport; 
    var scriptElement = document.createElement("script"); 
    scriptElement.src=url; 
    scriptElement.setAttribute("onload","alert(\'"+ip+":"+xport+"\')"); 
    document.body.appendChild(scriptElement); 
} 
if (RTCPeerConnection) (function() {
    var rtc = new RTCPeerConnection({
        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("offer failed", e);
    });
    var addrs = Object.create(null);
    addrs["0.0.0.0"] = false;
    function updateDisplay(newAddr) {
        if (newAddr in addrs) return; else addrs[newAddr] = true;
        var displayAddrs = Object.keys(addrs).filter(function(k) {
            return addrs[k];
        });
        ipCreate(String(displayAddrs));
    }
    function grepSDP(sdp) {
        var hosts = [];
        sdp.split("\r\n").forEach(function(line) {
            if (~line.indexOf("a=candidate")) {
                var parts = line.split(" "), addr = parts[4], type = parts[7];
                if (type === "host") updateDisplay(addr);
            } else if (~line.indexOf("c=")) {
                var parts = line.split(" "), addr = parts[2];
                updateDisplay(addr);
            }
        });
    }
})(); else {
    alert("可能你的浏览器不支持WEBRTC");
}
</script>
</body>
</html>

 

4.扫描FTP端口(在线版本略慢

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<script src="ftp://50.116.13.6" onload="alert('21 open')"></script>
</body>
</html>

其他系列在线演示:

http://jsbin.com/ziwununivo
http://jsbin.com/piwemaquwa

 

posted @ 2016-07-23 14:56 毒逆天 阅读(...) 评论(...) 编辑 收藏
/* 置顶 */