Skip to content

Instantly share code, notes, and snippets.

@danitool
Created December 21, 2016 12:26
Show Gist options
  • Save danitool/2f9de48550a85450304f1fd2d281d155 to your computer and use it in GitHub Desktop.
Save danitool/2f9de48550a85450304f1fd2d281d155 to your computer and use it in GitHub Desktop.
check if a MAC device exists on the local network and alerts by sending an email
#!/bin/sh
# MAC watchdog, checks if a MAC device exists on the local network and alerts by sending an email
# 2016 by danitool, Tki2000, txutxy
CORREO="mi correo@gmail.com"
MAC="00:11:22:33:44:55"
RANGO_IP=192.168.3.1-254
FLAG=0
while :
do
MACSTATE=`nmap -v -sP $RANGO_IP|grep $MAC`
if [ "$MACSTATE" ] && [ $FLAG -eq 0 ]; then
echo -e "Subject:María está en casa." | sendmail $CORREO
FLAG=1
elif [ -z "$MACSTATE" ] && [ $FLAG -eq 1 ]; then
echo -e "Subject:María se ha ido." | sendmail $CORREO
FLAG=0
fi
sleep 5m
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment