Created
September 29, 2017 18:47
-
-
Save Rycieos/f303924a7c769fa6671db511a53e65c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Takes a company name, prints registerd IP blocks for them | |
if [ "$1" = "-4" ]; then | |
ipv4_only="true" | |
shift | |
elif [ "$1" = "-6" ]; then | |
ipv6_only="true" | |
shift | |
fi | |
if [ -z "$1" ]; then | |
echo "Useage: $0 [-4|-6] 'company name'" | |
exit 1 | |
fi | |
db4="http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2.zip" | |
db6="http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum2v6.zip" | |
if [ -z "${ipv6_only}" ]; then | |
lines=$(curl -s "${db4}" | gunzip | grep -i "$1" | | |
sed 's/.*,.*,"//; s/"$//' | sort -u) | |
IFS=$'\n' | |
for line in $lines; do | |
echo "${line}" | |
as=$(echo "${line}" | sed 's/[^a-zA-Z0-9].*$//') | |
whois -h whois.radb.net -- "-i origin ${as}" | grep -Eo "([0-9.]+){4}/[0-9]+" | |
done | |
unset IFS | |
fi | |
if [ -z "${ipv4_only}" ]; then | |
curl -s "${db6}" | gunzip | grep -i "$1" | sort -n | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment