From 24338417a87d1403f0513dd29604abf7b46be200 Mon Sep 17 00:00:00 2001 From: Connor Olding Date: Thu, 3 Sep 2020 11:23:20 +0200 Subject: [PATCH] split and abstract block ranges into a function --- respodns/dns.py | 6 ++---- respodns/ips.py | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/respodns/dns.py b/respodns/dns.py index a5b4a06..9b4d0c4 100644 --- a/respodns/dns.py +++ b/respodns/dns.py @@ -53,7 +53,7 @@ async def getaddrs(server, domain, opts): def process_result(res, ip, check, opts: Options): - from .ips import is_bogon, blocks + from .ips import is_bogon, is_block_target from .util import right_now from .structs import Entry @@ -68,9 +68,7 @@ def process_result(res, ip, check, opts: Options): elif check.kind.startswith("bad"): reason = "okay" if "NXDOMAIN" in res else "redirect" - elif any(is_bogon(r) for r in res): - reason = "block" - elif any(blocked in res for blocked in blocks): + elif any(is_bogon(r) or is_block_target(r) for r in res): reason = "block" elif not any(len(r) > 0 and r[0].isdigit() for r in res): diff --git a/respodns/ips.py b/respodns/ips.py index 9c76855..a7773d6 100644 --- a/respodns/ips.py +++ b/respodns/ips.py @@ -82,11 +82,12 @@ blocks = { "217.175.53.72", } -for i in range(1, 255): - blocks.add(f"156.154.112.{i}") - blocks.add(f"156.154.113.{i}") - blocks.add(f"156.154.175.{i}") - blocks.add(f"156.154.176.{i}") +block_checks = [ + "156.154.112.", + "156.154.113.", + "156.154.175.", + "156.154.176.", +] gfw_ips = { "4.36.66.178", @@ -372,3 +373,9 @@ bogon_checks = [ def is_bogon(ip): return any(ip.startswith(check) for check in bogon_checks) + + +def is_block_target(ip): + if ip in blocks: + return True + return any(ip.startswith(check) for check in block_checks)