type: 收敛测试 schemas 与协议层类型
This commit is contained in:
@@ -110,20 +110,26 @@ class BaseWhitelistAdapter(ABC):
|
||||
return True, msg
|
||||
|
||||
# 当前IP已存在但备注不同,不处理
|
||||
if any(r.get('ip') == current_ip for r in records):
|
||||
logger.info(f"白名单IP {current_ip} 已存在(备注不同),无需重复添加")
|
||||
if any(r.get("ip") == current_ip for r in records):
|
||||
logger.info(
|
||||
f"白名单IP {current_ip} 已存在(备注不同),无需重复添加"
|
||||
)
|
||||
return True, f"白名单IP已存在: {current_ip}"
|
||||
|
||||
# 超过上限,删除最老的
|
||||
if len(memo_ips) >= keep_recent:
|
||||
to_delete = memo_ips[:len(memo_ips) - keep_recent + 1]
|
||||
to_delete = memo_ips[: len(memo_ips) - keep_recent + 1]
|
||||
for old_ip in to_delete:
|
||||
if not old_ip:
|
||||
continue
|
||||
logger.info(f"白名单同备注IP超限,删除旧的: {old_ip}")
|
||||
self.delete_ip(old_ip)
|
||||
time.sleep(1)
|
||||
|
||||
# 添加新IP
|
||||
logger.info(f"白名单添加新出口IP: {current_ip} (当前 {len(memo_ips)} 个同备注)")
|
||||
logger.info(
|
||||
f"白名单添加新出口IP: {current_ip} (当前 {len(memo_ips)} 个同备注)"
|
||||
)
|
||||
ok, resp = self.add_ip(current_ip)
|
||||
if ok:
|
||||
msg = f"白名单IP已添加: {current_ip}"
|
||||
@@ -152,10 +158,12 @@ def _get_local_exit_ip() -> Optional[str]:
|
||||
]
|
||||
for url in targets:
|
||||
try:
|
||||
response = requests.get(url, timeout=8, headers={"User-Agent": "Mozilla/5.0"})
|
||||
response = requests.get(
|
||||
url, timeout=8, headers={"User-Agent": "Mozilla/5.0"}
|
||||
)
|
||||
response.raise_for_status()
|
||||
text = response.text.strip()
|
||||
match = re.search(r'(\d{1,3}(?:\.\d{1,3}){3})', text)
|
||||
match = re.search(r"(\d{1,3}(?:\.\d{1,3}){3})", text)
|
||||
if match:
|
||||
return match.group(1)
|
||||
except Exception:
|
||||
@@ -174,7 +182,9 @@ def get_exit_ip_via_proxy(proxy: str) -> Optional[str]:
|
||||
for url in targets:
|
||||
try:
|
||||
response = requests.get(
|
||||
url, proxies=proxies, timeout=6,
|
||||
url,
|
||||
proxies=proxies,
|
||||
timeout=6,
|
||||
headers={"User-Agent": "Mozilla/5.0"},
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
||||
Reference in New Issue
Block a user