Skip to content

Commit 86c98c3

Browse files
committed
added capability of scanning only one IP
1 parent 85a4b2f commit 86c98c3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

example.htm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
// It's also possible to specify a target or subnet size
1515
//sonar.start(true, 2000, "192.168.0.1/24");
1616
//sonar.start(true, 2000, "/24");
17+
18+
// Or just one IP
19+
//sonar.start(true, 2000, "192.168.0.1/32");
20+
//sonar.start(true, 2000, "192.168.0.1");
1721
</script>
1822
</body>
1923
</html>

sonar.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,16 @@ var sonar = {
2626
}
2727

2828
// Separate IP and range, target[0] is the IP and target[1] is the range
29+
// If the range is not specified, we assume that only one IP should be scaned
2930
target = target.split( '/' );
31+
if( target[1] === undefined ) {
32+
target[1] = 32;
33+
}
34+
35+
// Check the specified IP range, /31 subnets are excluded because those only have reserved and broadcast addresses
36+
if( target[1] < 0 || target[1] > 32 || target[1] == 31 ) {
37+
return false;
38+
}
3039

3140
// This calls sonar.process_queue() every
3241
setInterval( function() {
@@ -36,7 +45,7 @@ var sonar = {
3645
if( target[0] == "" ) {
3746
sonar.enumerate_local_ips( target[1] );
3847
} else{
39-
sonar.ip_to_range( target[0], target[1] );
48+
sonar.ip_to_range( target[0], target[1] );
4049
}
4150
},
4251

@@ -128,9 +137,15 @@ var sonar = {
128137
return false;
129138
}
130139

131-
var ip_min = [0, 0, 0, 0];
132-
var ip_max = [0, 0, 0, 0];
133-
var r = 0;
140+
// If we're only going to scan one IP, queue it without calculating the range
141+
if ( range == 32 ){
142+
sonar.ip_queue.push( ip );
143+
return;
144+
}
145+
146+
var ip_min;
147+
var ip_max;
148+
var r;
134149

135150
for( var tmp = 0; tmp < 4; tmp++ ) {
136151

0 commit comments

Comments
 (0)