Created
March 16, 2014 08:35
-
-
Save aidilfbk/9580177 to your computer and use it in GitHub Desktop.
Filters the ARIN IP address delegations by a country code and parses it into CIDR notation. Wrote it based on http://blog.erben.sk/2014/01/28/generating-country-ip-ranges-lists/
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
#!/usr/bin/env sh | |
# based on http://blog.erben.sk/2014/01/28/generating-country-ip-ranges-lists/ | |
# change accordingly | |
country_code='US'; | |
# please reference the proper registry | |
# United States, Canada, several parts of the Caribbean region, and Antarctica: http://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest | |
# Europe, Russia, the Middle East, and Central Asia: http://ftp.ripe.net/ripe/stats/delegated-ripencc-latest | |
# Africa: http://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest | |
# Asia, Australia, New Zealand, and neighboring countries: http://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest | |
# Latin America and parts of the Caribbean region: http://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest | |
delegations_url='http://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest' | |
curl $delegations_url --silent | awk -v country_code=$country_code -F '|' 'BEGIN { pattern=country_code"\\|ipv4"; } $0 ~ pattern {print $4 "/" (32-log($5)/log(2)) }'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment