TringaliLuca

Scan network with fping for connected devices

Mar 18th, 2017
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. interface='wlan0'
  3. while true ; do
  4.    if ifconfig $interface | grep -q "inet" ; then
  5.       echo "Network is working"
  6.       myip=$(ifconfig $interface | grep -E 'inet |inet:' | awk -F'[: ]+' '{ print $4 }')
  7.       mynet=$(echo $myip | sed 's/\.[^.]*$//').0/24
  8.       echo $mynet
  9.       fping -c1 -g $mynet 2>/dev/null 1>/tmp/network.txt
  10.       clients=0
  11.       clients=$(wc -l < /tmp/network.txt)
  12.       if [ "$clients" -gt 2 ]
  13.       then
  14.        echo $clients" connected clients:"
  15.        cat /tmp/network.txt
  16.       fi
  17.       sleep 60
  18.    else
  19.       echo "No network."
  20.       sleep 10
  21.    fi
  22. done
RAW Paste Data