There are many sites providing country blocklists, for example http://www.ip2location.com/free/visitor-blocker or https://www.countryipblocks.net/. When you want periodicaly update such list, you have problem. You need pay for that service for automated access, actual data or “hack” access to that service (abuse their free access conditions)…
Is there some easy solution how to generate this ranges by yourself?
Small python script can help to get and parse ranges from RIPE
import math import urllib opener = urllib.FancyURLopener() f = opener.open("ftp://ftp.ripe.net/pub/stats/ripencc/delegated-ripencc-latest") lines=f.readlines() for line in lines: if (('ipv4' in line) & ('SK' in line)) : s=line.split("|") net=s[3] cidr=float(s[4]) print "%s/%d" % (net,(32-math.log(cidr,2)))
Alter this script as you need…
For other regions use proper Regional Internet Registries (RIRs):
ftp://ftp.arin.net/pub/stats/arin/delegated-arin-extended-latest
ftp://ftp.ripe.net/ripe/stats/delegated-ripencc-latest
ftp://ftp.afrinic.net/pub/stats/afrinic/delegated-afrinic-latest
ftp://ftp.apnic.net/pub/stats/apnic/delegated-apnic-latest
ftp://ftp.lacnic.net/pub/stats/lacnic/delegated-lacnic-latest
UPDATE: See my next post about country lists download from my generator.
UPDATE #2: Similar script in php using different source in this post.
I had no idea that the country/IP delegations were readily available. This is exactly what I needed. However, I wanted it to run on an OpenWRT installation and I didn’t want to install python, so I wrote a shell/curl/awk version.
[code]
#!/usr/bin/env sh
# change accordingly
country_code=’SK’;
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)) }’;
[/code]
Pingback: 8 Ways to Block Visitors to Your Website by Country • Raymond.CC
Fuckin awesome.
The valuable part of this is the knowledge that it can be scooped off of the registrars FTPs. Thank you for learning me this.
I wish I was smart enough to know how to implement this because it sounds like you know what you are talking about
It was really information, I was need some source which I can use to update my router’s list. Here is another link
http://www.ipaddresshost.com/downloads/cidrcountry is also providing the same thing as you did, don’t know when they will also block it. They have website also for this but I was need only cidr list 😀
Is EU superset of all EU countries IPs ? If so why are some IP ranges from Si missing in EU?
Hi, I have no idea from where EU data come from. RIPE database from their FTP is source of data.
BROKEN: module ‘urllib’ has no attribute ‘FancyURLopener’