MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / check_ip_location

Method check_ip_location

src/core/http_client.py:269–292  ·  view source on GitHub ↗

检查 IP 地理位置 Returns: Tuple[是否支持, 位置信息]

(self)

Source from the content-addressed store, hash-verified

267 }
268
269 def check_ip_location(self) -> Tuple[bool, Optional[str]]:
270 """
271 检查 IP 地理位置
272
273 Returns:
274 Tuple[是否支持, 位置信息]
275 """
276 try:
277 response = self.get("https://cloudflare.com/cdn-cgi/trace", timeout=10)
278 trace_text = response.text
279
280 # 解析位置信息
281 import re
282 loc_match = re.search(r"loc=([A-Z]+)", trace_text)
283 loc = loc_match.group(1) if loc_match else None
284
285 # 检查是否支持
286 if loc in ["CN", "HK", "MO", "TW"]:
287 return False, loc
288 return True, loc
289
290 except Exception as e:
291 logger.error(f"检查 IP 地理位置失败: {e}")
292 return False, None
293
294 def send_openai_request(
295 self,

Callers 1

_check_ip_locationMethod · 0.45

Calls 2

errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected