Flashpoint-Legendary

Untitled

Jul 20th, 2025
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. │ File: netcheck.sh
  2. ───────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  3. 1 │ #!/bin/bash
  4. 2 │ # by AustinMStaton I got bored in this is a fast way to see whats all on my homelab
  5. 3 │ # a Short way is to just run nmap -v -sn 192.168.0.1/24 | grep "Host is up" -B1 but is not the point lol
  6. 4 │
  7. 5 │ # A more powerful network scanner using fping for discovery and nmap for details.
  8. 6 │
  9. 7 │ # ====== 1. Initialization ======
  10. 8 │ # An array to store the IPs of all hosts that are found.
  11. 9 │ found_hosts=()
  12. 10 │
  13. 11 │ # ====== 2. Check for Required Tools ======
  14. 12 │ # Ensure fping and nmap are installed before running.
  15. 13 │ for tool in fping nmap; do
  16. 14 │ if ! command -v "$tool" &> /dev/null; then
  17. 15 │ echo -e "\033[31mError: '$tool' is not installed.\033[0m"
  18. 16 │ echo "Please install it to continue. (e.g., 'sudo apt install $tool')"
  19. 17 │ exit 1
  20. 18 │ fi
  21. 19 │ done
  22. 20 │
  23. 21 │ # ====== 3. Auto-Detect Network Range ======
  24. 22 │ # Automatically find the primary network address (e.g., 192.168.1.0/24).
  25. 23 │ NETWORK_RANGE=$(ip -o -4 addr show | awk '!/127.0.0.1/ {print $4}' | head -n 1)
  26. 24 │
  27. 25 │ if [ -z "$NETWORK_RANGE" ]; then
  28. 26 │ echo -e "\033[31mCould not auto-detect network range.\033[0m"
  29. 27 │ read -p "Please enter your network range (e.g., 192.168.1.0/24): " NETWORK_RANGE
  30. 28 │ fi
  31. 29 │
  32. 30 │ echo -e "\n\033[1;33mScanning network: $NETWORK_RANGE\033[0m"
  33. 31 │ echo "This may take a few moments..."
  34. 32 │
  35. 33 │ # ====== 4. Discover Live Hosts and Scan Them ======
  36. 34 │ # We use process substitution <(...) to feed the loop without creating a subshell.
  37. 35 │ # This ensures the found_hosts array is not lost after the loop.
  38. 36 │ while read -r ip; do
  39. 37 │ # For each live IP found, add it to our array
  40. 38 │ found_hosts+=("$ip")
  41. 39 │
  42. 40 │ # Print a clear header for the detailed scan
  43. 41 │ echo -e "\n\033[1;34m===========================================\033[0m"
  44. 42 │ echo -e "\033[1;32m[+] Host Found: $ip\033[0m"
  45. 43 │ echo -e "\033[1;34m===========================================\033[0m"
  46. 44 │
  47. 45 │ # Run nmap on the IP. If the script has root privileges, enable OS detection.
  48. 46 │ if [[ $EUID -eq 0 ]]; then
  49. 47 │ nmap -T4 -F -O --osscan-limit "$ip"
  50. 48 │ else
  51. 49 │ nmap -T4 -F "$ip"
  52. 50 │ fi
  53. 51 │ done < <(fping -a -g "$NETWORK_RANGE" 2>/dev/null)
  54. :
Advertisement
Add Comment
Please, Sign In to add comment