Skip to content

Instantly share code, notes, and snippets.

@subuk
Created May 26, 2018 13:12
Show Gist options
  • Save subuk/3f87e71a00765f1306eb5f89801d6317 to your computer and use it in GitHub Desktop.
Save subuk/3f87e71a00765f1306eb5f89801d6317 to your computer and use it in GitHub Desktop.
expand-blocklist.py
#!/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