Created
May 26, 2018 13:12
-
-
Save subuk/3f87e71a00765f1306eb5f89801d6317 to your computer and use it in GitHub Desktop.
expand-blocklist.py
This file contains hidden or 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 python | |
import csv | |
import codecs | |
import urllib.request | |
import argparse | |
import ipaddress | |
def iter_blocked_subnets(): | |
url = "https://raw.githubusercontent.com/zapret-info/z-i/master/dump.csv" | |
response = urllib.request.urlopen(url) | |
reader = csv.reader(codecs.iterdecode(response, 'cp1251'), delimiter=';') | |
for row in reader: | |
for ip in row[0].split(u' | '): | |
try: | |
yield ipaddress.ip_network(ip.strip()) | |
except (ipaddress.AddressValueError, ValueError): | |
pass | |
def reveal_subnets(blocked_subnets): | |
for subnet in blocked_subnets: | |
for ip in subnet: | |
yield ip | |
def main(): | |
for ip in reveal_subnets(iter_blocked_subnets()): | |
print(ip) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment