probe_gateway2.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. """Try the 3 DNS IPs of gfgame.dhsf.xqhuyu.com directly, on multiple ports,
  2. with a minimal CS 2001 probe. Some gateways reply with an error frame (503)
  3. even for malformed logins — that alone proves the framing is right.
  4. Also try a pure 8-byte or empty probe to see if the gateway sends anything
  5. at all upon connect (banner).
  6. """
  7. import asyncio
  8. import base64
  9. import json
  10. import os
  11. import sys
  12. from pathlib import Path
  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. from cq2_sdk.transport.tcp import TcpClient
  17. from cq2_sdk.transport.framing import encode_frame
  18. if hasattr(sys.stdout, "reconfigure"):
  19. sys.stdout.reconfigure(encoding="utf-8", errors="replace")
  20. IPS = ["47.118.169.147", "47.118.169.153", "47.118.172.233"]
  21. def get_creds() -> tuple[str, str]:
  22. text = Path(r"D:\ProgramFiles\996box\GameBoxDownload\1\env.json").read_bytes().decode("utf-8", errors="replace")
  23. idx = text.find("eyJ")
  24. b64 = text[idx:].rstrip()
  25. padded = b64 + "=" * (-len(b64) % 4)
  26. obj, _ = json.JSONDecoder().raw_decode(base64.urlsafe_b64decode(padded).decode("utf-8", errors="replace"))
  27. return str(obj.get("uid", "")), str(obj.get("token", ""))
  28. async def attempt(ip: str, port: int, uid: str, token: str, sid: int) -> None:
  29. label = f"{ip}:{port}"
  30. try:
  31. reader, writer = await asyncio.wait_for(asyncio.open_connection(ip, port), timeout=5)
  32. except Exception as e:
  33. print(f"{label:24s} connect: {type(e).__name__}")
  34. return
  35. try:
  36. # Send minimal CS 2001
  37. attach = f"{uid}/{token}/1/0".encode()
  38. frame = encode_frame(2001, 900000, 0, sid, 0, attach)
  39. writer.write(frame)
  40. await writer.drain()
  41. try:
  42. data = await asyncio.wait_for(reader.read(4096), timeout=6)
  43. if data:
  44. print(f"{label:24s} REPLY {len(data)}B: {data[:60].hex()}")
  45. else:
  46. print(f"{label:24s} connection closed by server (0 bytes)")
  47. except asyncio.TimeoutError:
  48. print(f"{label:24s} no reply (6s)")
  49. finally:
  50. writer.close()
  51. try:
  52. await writer.wait_closed()
  53. except Exception:
  54. pass
  55. async def main() -> None:
  56. uid, token = get_creds()
  57. sid = 14414738
  58. print(f"uid={uid} token_len={len(token)} sid={sid}")
  59. print()
  60. for ip in IPS:
  61. for port in (12000, 8001, 8021):
  62. await attempt(ip, port, uid, token, sid)
  63. print()
  64. print("--- also try raw banner read (connect, send nothing) on 12000 ---")
  65. try:
  66. reader, writer = await asyncio.wait_for(asyncio.open_connection(IPS[0], 12000), timeout=5)
  67. try:
  68. data = await asyncio.wait_for(reader.read(4096), timeout=4)
  69. print(f"banner: {data[:60]!r}" if data else "no banner (server waits for client)")
  70. except asyncio.TimeoutError:
  71. print("no banner within 4s (normal — server waits)")
  72. finally:
  73. writer.close()
  74. except Exception as e:
  75. print(f"banner connect failed: {e}")
  76. asyncio.run(main())