Skip to content

Instantly share code, notes, and snippets.

@aaronmelton
Last active December 30, 2015 20:37
Show Gist options
  • Select an option

  • Save aaronmelton/03aae1140ba5ea1f0808 to your computer and use it in GitHub Desktop.

Select an option

Save aaronmelton/03aae1140ba5ea1f0808 to your computer and use it in GitHub Desktop.
Port scan targets and send email w/ attachment if results different than previous execution.
#!/bin/sh
TARGETS="192.168.1.0/24"
FILENAME="nmap_192.168.1.0"
OPTIONS="-v -n --open -sS -sU -F --scan-delay 1s"
DATE=`date +%F`
cd /var/log/nmap
nmap $OPTIONS $TARGETS -oA $FILENAME\_$DATE > /dev/null
if [ -e $FILENAME\-prev.xml ]; then
ndiff $FILENAME\-prev.xml $FILENAME\_$DATE.xml > $FILENAME\-diff_$DATE.txt
if [ "$?" -eq "1" ]; then
echo "See attachment for NMAP differences." | mutt -s "NMAP Differences Discovered" -a $FILENAME\-diff_$DATE.txt -- user@email.com
fi
fi
ln -sf $FILENAME\_$DATE.xml $FILENAME\-prev.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment