Advertisement
rs232

discovery_2.0.sh

May 11th, 2024 (edited)
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.57 KB | None | 0 0
  1. #!/bin/sh
  2. export PATH=/bin:/usr/bin:/sbin:/usr/sbin:/home/root:
  3. # Network discovery script v2.0 - ARM and MIPSR2 - 05/2024 - rs232
  4. #------------------------------------------------------
  5. #    FreshTomato Network Discovery - usage
  6. #
  7. #    default (or arping) = arping scanning
  8. #    traceroute = uses a traceroute discovery
  9. #------------------------------------------------------
  10.  
  11. iplist() {
  12. input_cidr="$1"
  13. subnet_mask=$(echo "$input_cidr" | cut -d '/' -f 2)
  14. num_addresses=$((2 ** (32 - subnet_mask)))
  15. ip_address=$(echo "$input_cidr" | cut -d '/' -f 1)
  16. ip_int=0
  17. for octet in $(echo "$ip_address" | tr '.' ' '); do
  18.     ip_int=$((ip_int * 256 + octet))
  19. done
  20. first_ip_int=$((ip_int & ~(num_addresses - 1)))
  21. last_ip_int=$((first_ip_int + num_addresses - 1))
  22. for i in $(seq 1 $((num_addresses - 2))); do
  23.     current_ip_int=$((first_ip_int + i))
  24.     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))
  25. done
  26. }
  27.  
  28. [ "$(ps w | grep 'traceroute -i\ | arping -q' | grep -v grep | wc -l)" -gt 0 ] && {
  29.     logger "Device List Discovery already running - exiting ..."
  30.     exit
  31. }
  32.  
  33. for bridge in $(brctl show | grep -Eo ^br[0-9]); do
  34. cidr=$(ip addr list dev $bridge | grep inet | awk '{print $2}')
  35. ip=$(echo $cidr | cut -d/ -f1)
  36. iplist $cidr | while read -r ip_address; do
  37.         if [ -z $1 ] || [ $1 == "arping" ]; then usleep 1500 && arping -q -c1 -w1 -I $bridge $ip_address &>/dev/null &
  38.         elif [ $1 == "traceroute" ]; then traceroute -i $bridge -r -F -m1 -q1 -s $ip $ip_address &>/dev/null &
  39.         fi
  40. done
  41. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement