split and abstract block ranges into a function

This commit is contained in:
Connor Olding 2020-09-03 11:23:20 +02:00
parent 1c85e7b329
commit 24338417a8
2 changed files with 14 additions and 9 deletions

View file

@ -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):

View file

@ -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)