Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- LASTFILE=/var/lib/detectnewhosts.last
- SUBNET=192.168.0.0/24
- EMAILADDR=user@example.org
- SLEEPTIME=60
- echo -n "Detecting new hosts"
- while true ; do
- echo -n "."
- nmap -n -sn -PR -oX - "$SUBNET" > "$LASTFILE.new"
- if [ -e "$LASTFILE" ] ; then
- DIFF=$(ndiff "$LASTFILE" "$LASTFILE.new" | grep '^\+.*:$')
- if [ ! -z "$DIFF" ] ; then
- echo
- echo "$(date): " $DIFF
- if [ ! -z "$EMAILADDR" ] ; then
- echo "$DIFF" | mail -s "New hosts detected" "$EMAILADDR"
- fi
- fi
- fi
- mv -f "$LASTFILE.new" "$LASTFILE"
- sleep "$SLEEPTIME"
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement