Skip to content

Instantly share code, notes, and snippets.

@ole-tange
Created April 24, 2018 23:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ole-tange/35904f6c229b54f6fcb9bc2331bdae29 to your computer and use it in GitHub Desktop.
Save ole-tange/35904f6c229b54f6fcb9bc2331bdae29 to your computer and use it in GitHub Desktop.
Monitor top-10000 hosts from different places in the world. Give output of change.
#!/bin/bash
open_dns() {
# Look for open DNS at X.X.Y.Y
parallel -j0 --tag host -t a youtube.com {1}.{1}.{2}.{2} ::: {1..255} ::: {1..255} |
grep 'youtube.com has address' |
perl -pe 's/^(\d+) (\d+)\t.*/$1.$1.$2.$2/'
}
if [ ! -e open_dns_list ] ; then
# Create list of open DNS if it does not exist
open_dns > open_dns_list
fi
if [ ! -e top-1m.csv.zip ] ; then
# Download Alexa list if it does not exist
wget http://s3.amazonaws.com/alexa-static/top-1m.csv.zip
fi
# Unpack top-1m
zcat top-1m.csv.zip |
# Keep only top 10000
head -n10000 |
# Split list on ,
# Retry lookups 10 times if they fail
# Sort output because the order is not significant
# mispipe is needed to get the error code from host
# look up 'a' and 'mx' record
# on all open DNS servers
# save output to new
parallel -j0 -k --tagstring {3}-{1}-{4} --colsep , --retries 10 \
mispipe \"host -t {1} {3} {4}\" sort \
::: a mx \
:::: - \
:::: open_dns_list > new;
# Is there any difference from last run?
diff new old;
# Make this the basis for next run
mv new old
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment