This repository has been archived by the owner on May 14, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
6 changed files
with
96 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.project | ||
.settings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |