Create a gist now

Instantly share code, notes, and snippets.

@83leej /check
Created Nov 27, 2016

What would you like to do?
just a simple script that grabs two file if they are currently not there, allows checking for IP ranges by providing a simple name such as 'godaddy' or 'digitalocean', it then returns the results and provides a file name rangelist with the found ranges.
#!/bin/bash
NAMETOCHECK=$1
if [ ! -d asninfo ]; then
mkdir asninfo;
echo "Created: asninfo/";
fi
if [ ! -f asninfo/data-used-autnums.txt ]; then
curl http://thyme.apnic.net/current/data-used-autnums -o asninfo/data-used-autnums.txt
fi
if [ ! -f asninfo/data-raw-table.txt ]; then
curl http://thyme.apnic.net/current/data-raw-table -o asninfo/data-raw-table.txt
fi
echo ""
echo "#######################"
echo "ASN names for $NAMETOCHECK"
echo ""
grep -wi "$NAMETOCHECK" asninfo/data-used-autnums.txt > templist
ASNFOUND=0
COUNTER=0
rm rangelist
touch rangelist
while read ASN NAME
do
let ASNFOUND=ASNFOUND+1
echo " ------- [ $ASN ] ---------"
echo " -- $NAME"
echo " -- RANGES FOR ASN: $ASN"
grep -wi $ASN asninfo/data-raw-table.txt > templist2
while read RANGE ASN2
do
echo " --- $RANGE"
let COUNTER=COUNTER+1
echo "$RANGE" >> rangelist
done <templist2
rm templist2
done <templist
rm templist
echo " ------- [ FINISHED ] ---------"
echo " Found $ASNFOUND ASN match for $NAMETOCHECK"
echo " Total $COUNTER IP Ranges Found"
echo " Exported to file: rangelist"
echo ""
echo " IP Range Extractor By ctrlbox.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment