Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- USER="admin"
- PASS="passhere"
- PROTOCOL="http"
- ROUTER_IP="192.168.1.1"
- # Port to connect to which will provide the JSON data.
- PORT=9898
- while [ 1 ]
- do
- # Grab connected device MAC addresses through router status page.
- MACS=$(curl -s --user $USER:$PASS $PROTOCOL://$ROUTER_IP/Status_Wireless.live.asp)
- # clear temp JSON file
- echo > temp.log
- # Get hostname and IP (just in case there is no hostname).
- for MAC in $(echo $MACS | grep -oE "wl_mac::[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}:[a-z0-9]{2}" | cut -c 9-);
- do
- grep 0x /proc/net/arp | awk '{print $1 " " $4}' | while IFS= read -r line
- do
- IP=$(echo $line | cut -d' ' -f1)
- MACTEMP=$(echo $line | cut -d' ' -f2)
- HOST=$(arp -a | grep $IP | cut -d' ' -f1)
- # if no hostname exists, just use IP.
- if [ "$HOST" == "" ]
- then
- HOST=$IP
- fi
- if [ "$MAC" == "$MACTEMP" ]
- then
- JSON="{'hostname' : '$HOST', 'mac_address' : '$MAC'}"
- echo $JSON >> temp.log
- fi
- done
- done
- # Provide the JSON formatted output on $PORT of router.
- # This allows one connection before closing the port (connect, receive data, close).
- # Port will reopen every 5 minutes with new data as setup in a cron job.
- echo -e "HTTP/1.1 200 OKnn $(cat temp.log)" | nc -l -p$PORT >/dev/null
- # Wait for 10 seconds and do it all over.
- sleep 10
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement