split and abstract block ranges into a function
This commit is contained in:
parent
1c85e7b329
commit
24338417a8
2 changed files with 14 additions and 9 deletions
|
@ -53,7 +53,7 @@ async def getaddrs(server, domain, opts):
|
||||||
|
|
||||||
|
|
||||||
def process_result(res, ip, check, opts: Options):
|
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 .util import right_now
|
||||||
from .structs import Entry
|
from .structs import Entry
|
||||||
|
|
||||||
|
@ -68,9 +68,7 @@ def process_result(res, ip, check, opts: Options):
|
||||||
elif check.kind.startswith("bad"):
|
elif check.kind.startswith("bad"):
|
||||||
reason = "okay" if "NXDOMAIN" in res else "redirect"
|
reason = "okay" if "NXDOMAIN" in res else "redirect"
|
||||||
|
|
||||||
elif any(is_bogon(r) for r in res):
|
elif any(is_bogon(r) or is_block_target(r) for r in res):
|
||||||
reason = "block"
|
|
||||||
elif any(blocked in res for blocked in blocks):
|
|
||||||
reason = "block"
|
reason = "block"
|
||||||
|
|
||||||
elif not any(len(r) > 0 and r[0].isdigit() for r in res):
|
elif not any(len(r) > 0 and r[0].isdigit() for r in res):
|
||||||
|
|
|
@ -82,11 +82,12 @@ blocks = {
|
||||||
"217.175.53.72",
|
"217.175.53.72",
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in range(1, 255):
|
block_checks = [
|
||||||
blocks.add(f"156.154.112.{i}")
|
"156.154.112.",
|
||||||
blocks.add(f"156.154.113.{i}")
|
"156.154.113.",
|
||||||
blocks.add(f"156.154.175.{i}")
|
"156.154.175.",
|
||||||
blocks.add(f"156.154.176.{i}")
|
"156.154.176.",
|
||||||
|
]
|
||||||
|
|
||||||
gfw_ips = {
|
gfw_ips = {
|
||||||
"4.36.66.178",
|
"4.36.66.178",
|
||||||
|
@ -372,3 +373,9 @@ bogon_checks = [
|
||||||
|
|
||||||
def is_bogon(ip):
|
def is_bogon(ip):
|
||||||
return any(ip.startswith(check) for check in bogon_checks)
|
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)
|
||||||
|
|
Loading…
Reference in a new issue