Skip to content

Instantly share code, notes, and snippets.

@3m3x
Created September 13, 2019 11:45
Show Gist options
  • Save 3m3x/247d6319fa3481f8a95584105939fdec to your computer and use it in GitHub Desktop.
Save 3m3x/247d6319fa3481f8a95584105939fdec to your computer and use it in GitHub Desktop.
Nmap a target periodically and be updated on any changes
#!/bin/sh
#
# Taken from https://nmap.org/book/ndiff-man-periodic.html
#
# Add the following to your crontab to run the scan at 1PM each day:
#
# 0 13 * * * /home/YOUR_HOME_DIR/bin/nmap-scan-diff.sh
#
TARGETS="192.168.1.1"
OPTIONS="-v -T4 -F -sV"
date=`date +%F`
cd $HOME/nmap_scans
nmap $OPTIONS $TARGETS -oA scan-$date > /dev/null
if [ -e scan-prev.xml ]; then
ndiff scan-prev.xml scan-$date.xml > diff-$date
echo "*** NDIFF RESULTS ***"
cat diff-$date
echo
fi
echo "*** NMAP RESULTS ***"
cat scan-$date.nmap
ln -sf scan-$date.xml scan-prev.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment