Skip to content

Instantly share code, notes, and snippets.

@Rycieos
Created September 29, 2017 18:47
Show Gist options
  • Save Rycieos/f303924a7c769fa6671db511a53e65c6 to your computer and use it in GitHub Desktop.
Save Rycieos/f303924a7c769fa6671db511a53e65c6 to your computer and use it in GitHub Desktop.
#!/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