几个比较”有意思“的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,如需转载请自行联系原作者

相关文章
|
8月前
|
JavaScript 前端开发 测试技术
使用Selenium执行JavaScript脚本:探索Web自动化的新领域
本文介绍了如何在Selenium中使用JavaScript解决自动化测试中的复杂问题。Selenium的`execute_script`函数用于同步执行JS,例如滑动页面、操作时间控件等。在滑动操作示例中,通过JS将页面滚动到底部,点击下一页并获取页面信息。对于只读时间控件,利用JS去除readonly属性并设置新日期。使用JS扩展了Selenium的功能,提高了测试效率和精准度,适用于各种自动化测试场景。
|
8月前
|
JavaScript 前端开发 Java
liteflow规则引擎 执行Javascript脚本
liteflow规则引擎 执行Javascript脚本
226 1
|
2月前
|
JSON 移动开发 JavaScript
在浏览器执行js脚本的两种方式
【10月更文挑战第20天】本文介绍了在浏览器中执行HTTP请求的两种方式:`fetch`和`XMLHttpRequest`。`fetch`支持GET和POST请求,返回Promise对象,可以方便地处理异步操作。`XMLHttpRequest`则通过回调函数处理请求结果,适用于需要兼容旧浏览器的场景。文中还提供了具体的代码示例。
在浏览器执行js脚本的两种方式
|
4月前
|
JavaScript 前端开发
用JavaScript脚本将当地时间转换成其它时区
用JavaScript脚本将当地时间转换成其它时区
|
8月前
|
JavaScript 前端开发 NoSQL
【MongoDB 专栏】MongoDB 的 JavaScript 引擎与脚本执行
【5月更文挑战第11天】MongoDB 的 JavaScript 引擎允许在服务器端直接执行脚本,提升效率并实现定制化操作。脚本环境提供独立但与数据库关联的运行空间,引擎负责脚本的解析、编译和执行。执行过程包括脚本提交、解析、编译和执行四个步骤。掌握脚本逻辑设计和 JavaScript 语言特性对于高效利用这一功能至关重要。例如,通过脚本可以计算商品总销售额,增强数据库操作的灵活性。
133 1
【MongoDB 专栏】MongoDB 的 JavaScript 引擎与脚本执行
|
8月前
|
JavaScript 前端开发
Playwright执行 JavaScript 脚本:探索浏览器自动化的新境界
在Web自动化中,Playwright提供`page.evaluate()`和`page.evaluate_handle()`来执行JavaScript脚本。`page.evaluate()`返回脚本执行结果,而`page.evaluate_handle()`返回JSHandle。示例展示了如何使用它们,如打印网页标题、操作元素及获取页面内容。通过这些方法,可以处理常规方法难以操作的网页元素。
|
8月前
|
JavaScript 前端开发 开发者
如果你想在钉钉环境中运行JavaScript脚本
【2月更文挑战第17天】如果你想在钉钉环境中运行JavaScript脚本
201 6
|
8月前
|
Web App开发 缓存 JavaScript
|
8月前
|
JSON JavaScript 前端开发
JS逆向快速定位关键点之9大通用hook脚本
JS逆向快速定位关键点之9大通用hook脚本
357 0
|
8月前
|
监控 JavaScript 前端开发
统计项目代码行数轻松搞定:使用 Node.js 脚本自动统计代码量
统计项目代码行数轻松搞定:使用 Node.js 脚本自动统计代码量
273 0
下一篇
开通oss服务