probe_server_list.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. """Probe 996box server list with different hosts, methods, and headers.
  2. Tests:
  3. 1. GET api.996hezi.com with User-Agent + Referer (still 996SDK v2 sign)
  4. 2. GET list-box.dhsf.xqhuyu.com/box_serverlist/206923.txt (modlist host, srvlist sign)
  5. 3. GET list-box.dhsf.xqhuyu.com/box_serverlist/206923.txt (no sign, raw)
  6. """
  7. import asyncio
  8. import os
  9. import sys
  10. import time
  11. import hashlib
  12. import hmac
  13. sys.path.insert(0, os.path.join(os.path.dirname(__file__), os.pardir, "src"))
  14. from cq2_sdk.env_loader import load_env
  15. load_env()
  16. import httpx
  17. def srvlist_sign(path: str, key: str, ts: int) -> str:
  18. """MD5("data=" + path + "&key=" + key + "&time=" + ts) per cq2-01 sec 3.2."""
  19. s = f"data={path}&key={key}&time={ts}"
  20. return hashlib.md5(s.encode()).hexdigest()
  21. async def probe():
  22. signkey = os.environ.get("CQ2_SIGNKEY", "")
  23. print("=== Test 1: GET api.996hezi.com with User-Agent + Referer (996SDK v2 sign) ===")
  24. ts = int(time.time())
  25. params = {
  26. "gameid": "206923",
  27. "channel": "110585",
  28. "sdkChannel": "996box_pc",
  29. "isBoxLogin": "1",
  30. "time": str(ts),
  31. }
  32. sorted_keys = sorted(params.keys())
  33. canon = "\n".join(f"{k}={params[k]}" for k in sorted_keys)
  34. sign = hmac.new(signkey.encode(), canon.encode(), hashlib.sha1).hexdigest()
  35. params["sign"] = sign
  36. async with httpx.AsyncClient(timeout=15) as c:
  37. r = await c.get(
  38. "https://api.996hezi.com/userApi/v1/Server/list",
  39. params=params,
  40. headers={
  41. "User-Agent": "996Box/5.1.1.9007",
  42. "Referer": "https://api.996hezi.com/",
  43. },
  44. )
  45. print(f" status: {r.status_code}")
  46. try:
  47. data = r.json()
  48. print(f" code: {data.get('code')}, msg: {data.get('msg')}")
  49. except Exception:
  50. print(f" text: {r.text[:200]}")
  51. print()
  52. print("=== Test 2: list-box.dhsf.xqhuyu.com srvlist (modlist key) ===")
  53. modlist_key = "shPUZw4ncV5oJ3Hu"
  54. path = "/box_serverlist/206923.txt"
  55. ts = int(time.time())
  56. sign = srvlist_sign(path, modlist_key, ts)
  57. async with httpx.AsyncClient(timeout=15) as c:
  58. r = await c.get(
  59. f"https://list-box.dhsf.xqhuyu.com{path}",
  60. params={"time": str(ts), "sign": sign},
  61. headers={"User-Agent": "996Box/5.1.1.9007"},
  62. )
  63. print(f" status: {r.status_code}")
  64. print(f" content-type: {r.headers.get('content-type')}")
  65. print(f" text[:300]: {r.text[:300]}")
  66. print()
  67. print("=== Test 3: box_serverlist/206923.txt raw (no sign) ===")
  68. async with httpx.AsyncClient(timeout=15) as c:
  69. r = await c.get(
  70. "https://list-box.dhsf.xqhuyu.com/box_serverlist/206923.txt",
  71. headers={"User-Agent": "996Box/5.1.1.9007"},
  72. )
  73. print(f" status: {r.status_code}")
  74. print(f" text[:500]: {r.text[:500]}")
  75. asyncio.run(probe())