Skip to content

Instantly share code, notes, and snippets.

@Humoud
Created April 23, 2020 17:35
Show Gist options
  • Save Humoud/621bae48cfeabd09ec4dfc5828bb137f to your computer and use it in GitHub Desktop.
Save Humoud/621bae48cfeabd09ec4dfc5828bb137f to your computer and use it in GitHub Desktop.
Tracking Newly Registered Domains
#!/bin/bash
# upgraded and modified from: https://isc.sans.edu/forums/diary/Tracking+Newly+Registered+Domains/23127/
TODAY=`date --date="-1 day" +"%Y-%m-%d"`
PARAM=`echo -n "$TODAY.zip" | base64`
DESTDIR="/opt/dns/domains"
URL="https://whoisds.com/whois-database/newly-registered-domains/$PARAM/nrd"
USERAGENT="DataBot/1.0"
TEMPFILE=`mktemp /tmp/wget_XXXXXX.zip`
LOGFILE=`mktemp /tmp/wget_XXXXXX.log`
CSVFILE="/opt/dns/newdomains.csv"
# Check if the destination directory exists
[ -d "$DESTDIR" ] || mkdir -p "$DESTDIR"
# Ensure that the file does not exist already
[ -r "$DESTDIR/$TODAY.txt" ] && rm "$DESTDIR/$TODAY.txt"
echo "Getting[$TODAY]: $URL"
wget -o $LOGFILE -O $TEMPFILE --user-agent="$USERAGENT" $URL
RC=$?
if [ "$RC" != "0" ]; then
echo "[ERROR] Cannot fetch $URL"
cat $LOGFILE
else
unzip -d $DESTDIR $TEMPFILE >$LOGFILE 2>&1
RC=$?
if [ "$RC" != "0" ]; then
echo "[ERROR] Cannot unzip $TEMPFILE"
cat $LOGFILE
else
echo "newdomain" >$CSVFILE
mv "$DESTDIR/domain-names.txt" "$DESTDIR/$TODAY.txt"
cat "$DESTDIR/$TODAY.txt" >>$CSVFILE
rm $LOGFILE $TEMPFILE
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment