IamLupo

Untitled

Dec 20th, 2025
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. import socket
  2. import threading
  3. from http.server import BaseHTTPRequestHandler, HTTPServer
  4.  
  5. # ---------------------------
  6. # TCP 10012: IP Mapping Server
  7. # ---------------------------
  8.  
  9. class IPMappingHandler(BaseHTTPRequestHandler):
  10. def log_message(self, format, *args):
  11. # Override to prevent default logging
  12. print(f"[HTTP] {self.command} {self.path}")
  13.  
  14. def do_GET(self):
  15. try:
  16. if self.path.startswith("/ipmapping-rest/otgc/IPMapping/battleroyale/location"):
  17. json_response = b'{"location": {"latitude": 37.7749, "longitude": -122.4194}, "countryName": "United States","countryCode": "US","region": "NA","city": "unknown"}'
  18.  
  19. self.send_response(200)
  20. self.send_header("Content-Type", "application/json")
  21. self.send_header("Content-Length", str(len(json_response))) # empty JSON body
  22. self.send_header("Connection", "Keep-Alive")
  23. self.end_headers()
  24. self.wfile.write(json_response)
  25. else:
  26. self.send_response(404)
  27. self.end_headers()
  28. self.wfile.write(b"")
  29. except (ConnectionResetError, BrokenPipeError):
  30. # Client closed connection before server finished sending
  31. print(f"[HTTP] Client disconnected prematurely: {self.client_address}")
  32.  
  33. def run_ipmapper_server(host="0.0.0.0", port=10012):
  34. server = HTTPServer((host, port), IPMappingHandler)
  35. print(f"[+] IP Mapper listening on {host}:{port}")
  36. server.serve_forever()
  37.  
  38.  
  39. # ---------------------------
  40. # TCP 10023: Matchmaker Server
  41. # ---------------------------
  42.  
  43. def tcp_matchmaker_handler(conn, addr):
  44. print(f"[TCP] Connection from {addr}")
  45. try:
  46. while True:
  47. data = conn.recv(4096)
  48. if not data:
  49. break
  50. print(f"[TCP] Received {len(data)} bytes from {addr}")
  51. print(repr(data))
  52. except Exception as e:
  53. print(f"[TCP] Error: {e}")
  54. finally:
  55. conn.close()
  56. print(f"[TCP] Connection closed {addr}")
  57.  
  58. def run_tcp_matchmaker(host="0.0.0.0", port=10023):
  59. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  60. s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
  61. s.bind((host, port))
  62. s.listen()
  63. print(f"[+] TCP Matchmaker listening on {host}:{port}")
  64. while True:
  65. conn, addr = s.accept()
  66. threading.Thread(target=tcp_matchmaker_handler, args=(conn, addr), daemon=True).start()
  67.  
  68.  
  69. # ---------------------------
  70. # UDP 10023: Matchmaker Server
  71. # ---------------------------
  72.  
  73. def run_udp_matchmaker(host="0.0.0.0", port=10023):
  74. s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  75. s.bind((host, port))
  76. print(f"[+] UDP Matchmaker listening on {host}:{port}")
  77. while True:
  78. data, addr = s.recvfrom(4096)
  79. print(f"[UDP] Received {len(data)} bytes from {addr}")
  80. print(repr(data))
  81.  
  82.  
  83. # ---------------------------
  84. # Run servers in threads
  85. # ---------------------------
  86.  
  87. if __name__ == "__main__":
  88. threading.Thread(target=run_ipmapper_server, daemon=True).start()
  89. threading.Thread(target=run_tcp_matchmaker, daemon=True).start()
  90. threading.Thread(target=run_udp_matchmaker, daemon=True).start()
  91.  
  92. print("[*] All servers running. Press Ctrl+C to exit.")
  93. try:
  94. while True:
  95. pass
  96. except KeyboardInterrupt:
  97. print("\n[*] Shutting down")
Advertisement
Add Comment
Please, Sign In to add comment