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

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!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(在线地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<! 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版本(在线地址

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<! 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 t; 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端口(在线版本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<! 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端口(在线版本略慢

1
2
3
4
5
6
7
8
9
10
<! 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

 


本文转自毒逆天博客园博客,原文链接:http://www.cnblogs.com/dunitian/p/5698718.html,如需转载请自行联系原作者

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值