Skip to content
This repository has been archived by the owner on May 14, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
rewrote the code to iterate html elements with a specific class
  • Loading branch information
aabeling committed Aug 15, 2013
1 parent 31b730d commit 21a2788
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 52 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
.project
.settings
1 change: 0 additions & 1 deletion README

This file was deleted.

9 changes: 9 additions & 0 deletions README.md
@@ -0,0 +1,9 @@
Port scanning with Javascript

The index.html shows how it can be used.
Further notes about the implementation can be
found in portscanner.js (use the source, Luke).

The portscanning function is taken from
http://www.gnucitizen.org/blog/javascript-port-scanner/
written by Petko Petkov.
54 changes: 33 additions & 21 deletions index.html
@@ -1,24 +1,36 @@
<html>
<head>
<script src="jsportscanner.js" type="text/javascript"></script>
<script type="text/javascript">
<!--

function check() {
var host = document.getElementById('host').value;
var port = document.getElementById('port').value;
AttackAPI.PortScanner.scanTarget(function(target,port,result) {
alert(target + ":" + port + " " + result);
}, host, [port], 1000);
}
-->
</script>
</head>
<body>
<form>
Host: <input type="text" id="host" name="host" length="20" />
Port: <input type="text" id="port" name="port" length="6" />
<input type="submit" value="Check" onclick="check();return false" />
</body>
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"
type="text/javascript"></script>
<script
src="portscanner.js"
type="text/javascript"></script>
<script>
$(document).ready(function() {
portscanner.init();
});
</script>
</head>
<body>
<table>
<tr>
<th>host:port</th>
<th>status</th>
</tr>
<tr>
<td>github.com:443</td>
<td><span class="portscanner">github.com:443</span></td>
</tr>
<tr>
<td>github.com:80</td>
<td><span class="portscanner">github.com:80</span></td>
</tr>
<tr>
<td>github.com:8080</td>
<td><span class="portscanner">github.com:8080</span></td>
</tr>
</table>
</body>

</html>
30 changes: 0 additions & 30 deletions jsportscanner.js

This file was deleted.

52 changes: 52 additions & 0 deletions portscanner.js
@@ -0,0 +1,52 @@
function PortScanner() {
/* intentionally left blank */
}

PortScanner.prototype.init = function() {

var self = this;

/* iterate over all elements with class "portscanner" */
$(".portscanner").each(function(index) {

/* split the content of the element into host and port */
var target = $(this).text();
var parts = target.split(":");
var host = parts[0];
var port = parts[1];

/* perform the check for the host and port */
var element = $(this);
self.check(function(target,port,status) {

/* put the status into the element */
element.text(status);
}, host, port, 1000);
});
};

/**
* Taken from http://www.gnucitizen.org/blog/javascript-port-scanner/
*/
PortScanner.prototype.check = function (callback, target, port, timeout) {

var timeout = (timeout == null)?100:timeout;
var img = new Image();

img.onerror = function () {
if (!img) return;
img = undefined;
callback(target, port, 'open');
};

img.onload = img.onerror;
img.src = 'http://' + target + ':' + port;

setTimeout(function () {
if (!img) return;
img = undefined;
callback(target, port, 'closed');
}, timeout);
};

var portscanner = new PortScanner();

0 comments on commit 21a2788

Please sign in to comment.