@@ -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