Geoffrey Frogeye
7937496882
While I'm automating this you'll need to download the A set from https://opendata.rapid7.com/sonar.fdns_v2/ to the file a.json.gz.
41 lines
1.1 KiB
Python
Executable file
41 lines
1.1 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
|
|
import database
|
|
import argparse
|
|
import sys
|
|
import ipaddress
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
# Parsing arguments
|
|
parser = argparse.ArgumentParser(
|
|
description="TODO")
|
|
parser.add_argument(
|
|
'type',
|
|
choices={'subdomains', 'ip4network'},
|
|
help="Type of rule inputed")
|
|
parser.add_argument(
|
|
'-i', '--input', type=argparse.FileType('r'), default=sys.stdin,
|
|
help="List of domains domains to block (with their subdomains)")
|
|
parser.add_argument(
|
|
'-f', '--first-party', action='store_true',
|
|
help="The input only comes from verified first-party sources")
|
|
args = parser.parse_args()
|
|
|
|
database.open_db()
|
|
|
|
if args.type == 'subdomains':
|
|
for rule in args.input:
|
|
database.feed_rule_subdomains(
|
|
rule.strip(), first_party=args.first_party)
|
|
elif args.type == 'ip4network':
|
|
for rule in args.input:
|
|
network = ipaddress.ip_network(rule.strip())
|
|
database.feed_rule_ip4network(
|
|
network, first_party=args.first_party)
|
|
else:
|
|
assert False
|
|
|
|
database.close_db()
|