diff --git a/release/src-rt-6.x.4708/router/others/discovery.sh b/release/src-rt-6.x.4708/router/others/discovery.sh index 4fb9daaee9..df58fa6e3f 100755 --- a/release/src-rt-6.x.4708/router/others/discovery.sh +++ b/release/src-rt-6.x.4708/router/others/discovery.sh @@ -1,6 +1,6 @@ #!/bin/sh export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/home/root: -# Network discovery script v1.7 - ARM and MIPS R2 - 06/2021 - rs232 +# Network discovery script v2.0 - ARM and MIPSR2 - 05/2024 - rs232 #------------------------------------------------------ # FreshTomato Network Discovery - usage # @@ -8,24 +8,34 @@ export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/home/root: # traceroute = uses a traceroute discovery #------------------------------------------------------ +iplist() { +input_cidr="$1" +subnet_mask=$(echo "$input_cidr" | cut -d '/' -f 2) +num_addresses=$((2 ** (32 - subnet_mask))) +ip_address=$(echo "$input_cidr" | cut -d '/' -f 1) +ip_int=0 +for octet in $(echo "$ip_address" | tr '.' ' '); do + ip_int=$((ip_int * 256 + octet)) +done +first_ip_int=$((ip_int & ~(num_addresses - 1))) +last_ip_int=$((first_ip_int + num_addresses - 1)) +for i in $(seq 1 $((num_addresses - 2))); do + current_ip_int=$((first_ip_int + i)) + printf "%d.%d.%d.%d\n" $((current_ip_int >> 24 & 255)) $((current_ip_int >> 16 & 255)) $((current_ip_int >> 8 & 255)) $((current_ip_int & 255)) +done +} + [ "$(ps w | grep 'traceroute -i\ | arping -q' | grep -v grep | wc -l)" -gt 0 ] && { logger "Device List Discovery already running - exiting ..." exit } for bridge in $(brctl show | grep -Eo ^br[0-9]); do - NETWORK=$(ifconfig $bridge | grep inet | awk '{print $2}' | grep -Eo "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3})*") - ip=$(ifconfig $bridge | grep inet | awk '{print $2}' | cut -d: -f2) - mask=$(ifconfig $bridge | grep inet | awk '{print $4}' | cut -f2 -d":" | head -1) - i4=$(echo $ip | awk -F"." '{print $4}') - m4=$(echo $mask | awk -F"." '{print $4}') - NETSTART=$(((i4 & m4)+1)) - NETEND=$(((i4 & m4 | 255-m4)-1)) - while [ "$NETSTART" -le "$NETEND" ]; do - HOST=$NETWORK$NETSTART - if [ -z $1 ] || [ $1 == "arping" ]; then usleep 1500 && arping -q -c1 -w1 -I $bridge $HOST &>/dev/null & - elif [ $1 == "traceroute" ]; then traceroute -i $bridge -r -F -m1 -q1 -s $ip $HOST &>/dev/null & + cidr=$(ip addr list dev $bridge | grep inet | awk '{print $2}') + ip=$(echo $cidr | cut -d/ -f1) + iplist $cidr | while read -r ip_address; do + if [ -z $1 ] || [ $1 == "arping" ]; then usleep 1500 && arping -q -c1 -w1 -I $bridge $ip_address &>/dev/null & + elif [ $1 == "traceroute" ]; then traceroute -i $bridge -r -F -m1 -q1 -s $ip $ip_address &>/dev/null & fi - NETSTART=$(($NETSTART+1)) done done