Skip to content

Commit b6ef2dc

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

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

example.htm

+4
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

+16-1
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,6 +137,12 @@ var sonar = {
128137
return false;
129138
}
130139

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+
131146
var ip_min = [0, 0, 0, 0];
132147
var ip_max = [0, 0, 0, 0];
133148
var r = 0;

0 commit comments

Comments
 (0)