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