Advertisement
elradix

Router Wifi Notification

May 31st, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.17 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. oldlist=/tmp/assoclist.old
  4. newlist=/tmp/assoclist.new
  5. touch $oldlist          # Create an empty file the first time through
  6.  
  7. while sleep 15
  8. do
  9.         for iface in $(nvram get wl_ifnames) $(nvram get wl0_vifs) $(nvram get wl1_vifs)
  10.         do
  11.                 wl -i $iface assoclist >> $newlist
  12.                 sed -i "s/assoclist/$iface/g" $newlist
  13.         done
  14.  
  15.         grep -vxFf $newlist $oldlist | while read macinfo
  16.         do
  17.                 macaddr="${macinfo#* }"
  18.                 arpinfo="$(arp -a | grep -iF $macaddr | awk '{print $1 " " $2}')"
  19.                 logger -t wireless $macinfo $arpinfo "has disconnected."
  20.                 telegram-cli -WR -e "msg @mybot \"WiFi - $macinfo \n$arpinfo has disconnected.\" "
  21.         done
  22.  
  23.         grep -vxFf $oldlist $newlist | while read macinfo
  24.         do
  25.                 macaddr="${macinfo#* }"
  26.                 arpinfo="$(arp -a | grep -iF $macaddr | awk '{print $1 " " $2}')"
  27.                 logger -t wireless $macinfo $arpinfo "has connected."
  28.                 telegram-cli -WR -e "msg @mybot \"WiFi - $macinfo \n$arpinfo has connected.\" "
  29.  
  30.         done
  31.  
  32.         mv $newlist $oldlist
  33. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement