BaSs_HaXoR

Termux (root) Hotspot LAN scanner

Feb 15th, 2026 (edited)
4,844
1
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.75 KB | None | 1 0
  1. #!/data/data/com.termux/files/usr/bin/bash
  2.  
  3. # Combined Hotspot Scanner Script
  4. # This script handles root permissions automatically
  5.  
  6. echo "=================================="
  7. echo "   Hotspot Network Scanner"
  8. echo "=================================="
  9.  
  10. # Check if running as root
  11. if [ "$EUID" -eq 0 ]; then
  12.     # We're already root, run the scan directly
  13.     CURRENT_SCRIPT=$(readlink -f "$0")
  14.     SCRIPT_DIR=$(dirname "$CURRENT_SCRIPT")
  15.    
  16.     # Get your IP and network
  17.     MY_IP=$(ip addr show | grep -E "wlan[0-9]" | grep "inet " | awk '{print $2}' | cut -d/ -f1 | head -1)
  18.    
  19.     if [ -z "$MY_IP" ]; then
  20.         # Try common hotspot interfaces
  21.         for IFACE in wlan1 wlan0 ap0; do
  22.             MY_IP=$(ip addr show $IFACE 2>/dev/null | grep "inet " | awk '{print $2}' | cut -d/ -f1)
  23.             [ -n "$MY_IP" ] && break
  24.         done
  25.     fi
  26.    
  27.     NETWORK=$(echo $MY_IP | cut -d. -f1-3)
  28.    
  29.     echo "Your IP: $MY_IP"
  30.     echo "Scanning network: $NETWORK.0/24"
  31.     echo "=================================="
  32.     echo ""
  33.    
  34.     # ARP cache check (needs root)
  35.     if [ -r /proc/net/arp ]; then
  36.         echo "[*] Checking ARP cache..."
  37.         cat /proc/net/arp 2>/dev/null | grep -v "IP address" | while read line; do
  38.             MAC=$(echo $line | awk '{print $4}')
  39.             if [ "$MAC" != "00:00:00:00:00:00" ] && [ "$MAC" != "" ] && [ "$MAC" != "00:00:00:00:00:00" ]; then
  40.                 IP=$(echo $line | awk '{print $1}')
  41.                 # Skip if IP is 0.0.0.0
  42.                 if [ "$IP" != "0.0.0.0" ]; then
  43.                     echo "Found: $IP -> $MAC"
  44.                 fi
  45.             fi
  46.         done
  47.     fi
  48.    
  49.     # Ping scan
  50.     echo ""
  51.     echo "[*] Performing ping scan (this will take about 30 seconds)..."
  52.     echo "Active devices:"
  53.    
  54.     # Create temp file
  55.     TEMP_FILE=/data/local/tmp/ping_results.txt
  56.     > $TEMP_FILE
  57.    
  58.     # Scan IPs 1-254
  59.     i=1
  60.     while [ $i -le 254 ]; do
  61.         ping -c 1 -W 1 $NETWORK.$i > /dev/null 2>&1 &
  62.         i=$((i + 1))
  63.     done
  64.    
  65.     # Wait for pings to complete
  66.     sleep 3
  67.    
  68.     # Check which IPs responded
  69.     i=1
  70.     while [ $i -le 254 ]; do
  71.         IP="$NETWORK.$i"
  72.         # Skip our own IP
  73.         if [ "$IP" != "$MY_IP" ]; then
  74.             # Check ARP for MAC
  75.             arp -n $IP 2>/dev/null | grep -v "incomplete" | grep "$IP" | while read line; do
  76.                 MAC=$(echo $line | awk '{print $3}')
  77.                 if [ "$MAC" != "(incomplete)" ] && [ "$MAC" != "" ]; then
  78.                     echo "$IP - $MAC"
  79.                 fi
  80.             done
  81.         fi
  82.         i=$((i + 1))
  83.     done
  84.    
  85.     # Also try to get from ping (for non-ARP devices)
  86.     i=1
  87.     while [ $i -le 254 ]; do
  88.         IP="$NETWORK.$i"
  89.         if [ "$IP" != "$MY_IP" ]; then
  90.             ping -c 1 -W 1 $IP > /dev/null 2>&1
  91.             if [ $? -eq 0 ]; then
  92.                 # Check if we already found it via ARP
  93.                 if ! arp -n $IP 2>/dev/null | grep -q "$IP"; then
  94.                     echo "$IP - (no MAC)"
  95.                 fi
  96.             fi
  97.         fi
  98.         i=$((i + 1))
  99.     done
  100.    
  101.     rm -f $TEMP_FILE
  102.    
  103.     echo ""
  104.     echo "=================================="
  105.     echo "Scan complete!"
  106.    
  107. else
  108.     # Not root, try to re-run with root
  109.     echo "[*] Not running as root. Attempting to gain root privileges..."
  110.    
  111.     # Check if we have su
  112.     if command -v su >/dev/null 2>&1; then
  113.         echo "[*] Using su to get root..."
  114.         # Get the full path of this script
  115.         SCRIPT_PATH=$(readlink -f "$0")
  116.         # Re-run with root
  117.         exec su -c "sh $SCRIPT_PATH"
  118.     else
  119.         echo "[!] su not found. Running without root (limited functionality)..."
  120.         # Run without root
  121.         exec sh "$0"
  122.     fi
  123. fi
Advertisement