mirror of
https://github.com/itdoginfo/allow-domains.git
synced 2026-04-06 14:51:12 +03:00
Fix: fix from copilot
This commit is contained in:
@@ -96,6 +96,7 @@ def mikrotik_fwd(src, out, remove={'google.com'}):
|
|||||||
|
|
||||||
def lines_from_file(filepath):
|
def lines_from_file(filepath):
|
||||||
if not os.path.exists(filepath):
|
if not os.path.exists(filepath):
|
||||||
|
print(f"Warning: input file not found: {filepath}", file=sys.stderr)
|
||||||
return []
|
return []
|
||||||
with open(filepath, 'r', encoding='utf-8') as f:
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
return [line.strip() for line in f if line.strip()]
|
return [line.strip() for line in f if line.strip()]
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ def fetch_asn_prefixes(asn_list):
|
|||||||
url = RIPE_STAT_URL.format(asn)
|
url = RIPE_STAT_URL.format(asn)
|
||||||
req = make_request(url)
|
req = make_request(url)
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req) as response:
|
with urllib.request.urlopen(req, timeout=30) as response:
|
||||||
data = json.loads(response.read().decode('utf-8'))
|
data = json.loads(response.read().decode('utf-8'))
|
||||||
for entry in data['data']['prefixes']:
|
for entry in data['data']['prefixes']:
|
||||||
prefix = entry['prefix']
|
prefix = entry['prefix']
|
||||||
@@ -94,7 +94,7 @@ def download_subnets(*urls):
|
|||||||
for url in urls:
|
for url in urls:
|
||||||
req = make_request(url)
|
req = make_request(url)
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req) as response:
|
with urllib.request.urlopen(req, timeout=30) as response:
|
||||||
subnets = response.read().decode('utf-8').splitlines()
|
subnets = response.read().decode('utf-8').splitlines()
|
||||||
for subnet_str in subnets:
|
for subnet_str in subnets:
|
||||||
try:
|
try:
|
||||||
@@ -118,7 +118,7 @@ def download_aws_cloudfront_subnets():
|
|||||||
|
|
||||||
req = make_request(AWS_CIDR_URL)
|
req = make_request(AWS_CIDR_URL)
|
||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(req) as response:
|
with urllib.request.urlopen(req, timeout=30) as response:
|
||||||
data = json.loads(response.read().decode('utf-8'))
|
data = json.loads(response.read().decode('utf-8'))
|
||||||
|
|
||||||
for prefix in data.get('prefixes', []):
|
for prefix in data.get('prefixes', []):
|
||||||
|
|||||||
Reference in New Issue
Block a user