Rules lists are optional
This commit is contained in:
parent
a5e768fe00
commit
cbb0cc6f3b
|
@ -21,6 +21,8 @@ RULES_IP: typing.Set[ipaddress.IPv4Network] = set()
|
||||||
|
|
||||||
|
|
||||||
def subdomain_matching(subdomain: str) -> bool:
|
def subdomain_matching(subdomain: str) -> bool:
|
||||||
|
if not RULES_DICT:
|
||||||
|
return False
|
||||||
parts = subdomain.split('.')
|
parts = subdomain.split('.')
|
||||||
parts.reverse()
|
parts.reverse()
|
||||||
dic = RULES_DICT
|
dic = RULES_DICT
|
||||||
|
@ -34,6 +36,8 @@ def subdomain_matching(subdomain: str) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def ip_matching(ip_str: str) -> bool:
|
def ip_matching(ip_str: str) -> bool:
|
||||||
|
if not RULES_IP:
|
||||||
|
return False
|
||||||
ip = ipaddress.ip_address(ip_str)
|
ip = ipaddress.ip_address(ip_str)
|
||||||
for net in RULES_IP:
|
for net in RULES_IP:
|
||||||
if ip in net:
|
if ip in net:
|
||||||
|
@ -94,10 +98,10 @@ if __name__ == '__main__':
|
||||||
'-n', '--no-explicit', action='store_true',
|
'-n', '--no-explicit', action='store_true',
|
||||||
help="Don't output domains already blocked with rules without CNAME")
|
help="Don't output domains already blocked with rules without CNAME")
|
||||||
parser.add_argument(
|
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)")
|
help="List of domains domains to block (with their subdomains)")
|
||||||
parser.add_argument(
|
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")
|
help="List of IPs ranges to block")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -113,10 +117,12 @@ if __name__ == '__main__':
|
||||||
progress = progressbar.ProgressBar(widgets=widgets)
|
progress = progressbar.ProgressBar(widgets=widgets)
|
||||||
|
|
||||||
# Reading rules
|
# Reading rules
|
||||||
for rule in args.rules:
|
if args.rules:
|
||||||
register_rule(rule.strip())
|
for rule in args.rules:
|
||||||
for rule in args.rules_ip:
|
register_rule(rule.strip())
|
||||||
register_rule_ip(rule.strip())
|
if args.rules_ip:
|
||||||
|
for rule in args.rules_ip:
|
||||||
|
register_rule_ip(rule.strip())
|
||||||
|
|
||||||
# Approximating line count
|
# Approximating line count
|
||||||
if args.input.seekable():
|
if args.input.seekable():
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Eulerian
|
# Eulerian (AS50234 EULERIAN TECHNOLOGIES S.A.S.)
|
||||||
109.232.192.0/21
|
109.232.192.0/21
|
||||||
# Criteo
|
# Criteo (TODO More AS)
|
||||||
178.250.0.0/21
|
178.250.0.0/21
|
||||||
91.212.98.0/24
|
91.212.98.0/24
|
||||||
91.199.242.0/24
|
91.199.242.0/24
|
||||||
|
|
Loading…
Reference in a new issue