Rules lists are optional

This commit is contained in:
Geoffrey Frogeye 2019-12-07 18:17:53 +01:00
parent a5e768fe00
commit cbb0cc6f3b
2 changed files with 14 additions and 8 deletions

View file

@ -21,6 +21,8 @@ RULES_IP: typing.Set[ipaddress.IPv4Network] = set()
def subdomain_matching(subdomain: str) -> bool:
if not RULES_DICT:
return False
parts = subdomain.split('.')
parts.reverse()
dic = RULES_DICT
@ -34,6 +36,8 @@ def subdomain_matching(subdomain: str) -> bool:
def ip_matching(ip_str: str) -> bool:
if not RULES_IP:
return False
ip = ipaddress.ip_address(ip_str)
for net in RULES_IP:
if ip in net:
@ -94,10 +98,10 @@ if __name__ == '__main__':
'-n', '--no-explicit', action='store_true',
help="Don't output domains already blocked with rules without CNAME")
parser.add_argument(
'-r', '--rules', type=argparse.FileType('r'), default='rules',
'-r', '--rules', type=argparse.FileType('r'),
help="List of domains domains to block (with their subdomains)")
parser.add_argument(
'-p', '--rules-ip', type=argparse.FileType('r'), default='rules-ip',
'-p', '--rules-ip', type=argparse.FileType('r'),
help="List of IPs ranges to block")
args = parser.parse_args()
@ -113,10 +117,12 @@ if __name__ == '__main__':
progress = progressbar.ProgressBar(widgets=widgets)
# Reading rules
for rule in args.rules:
register_rule(rule.strip())
for rule in args.rules_ip:
register_rule_ip(rule.strip())
if args.rules:
for rule in args.rules:
register_rule(rule.strip())
if args.rules_ip:
for rule in args.rules_ip:
register_rule_ip(rule.strip())
# Approximating line count
if args.input.seekable():

View file

@ -1,6 +1,6 @@
# Eulerian
# Eulerian (AS50234 EULERIAN TECHNOLOGIES S.A.S.)
109.232.192.0/21
# Criteo
# Criteo (TODO More AS)
178.250.0.0/21
91.212.98.0/24
91.199.242.0/24