Yeah even python is possible. If you say something, you better share the code.
import socket
import threading
# Configuration for login-server
LOGIN_SERVER_PROXY_HOST = '45.118.132.189'
LOGIN_SERVER_PROXY_PORT = 6050
LOGIN_SERVER_TARGET_HOST = 'xx.xx.xx.xx'
LOGIN_SERVER_TARGET_PORT = 6050
# Configuration for char-server
CHAR_SERVER_PROXY_HOST = '45.118.132.189'
CHAR_SERVER_PROXY_PORT = 6051
CHAR_SERVER_TARGET_HOST = 'xx.xx.xx.xx'
CHAR_SERVER_TARGET_PORT = 6051
# Configuration for map-server
MAP_SERVER_PROXY_HOST = '45.118.132.189'
MAP_SERVER_PROXY_PORT = 6052
MAP_SERVER_TARGET_HOST = 'xx.xx.xx.xx'
MAP_SERVER_TARGET_PORT = 6052
# Forward traffic between source and destination sockets
def forward_traffic(source_socket, destination_socket):
while True:
data = source_socket.recv(4096)
if len(data) == 0:
break
destination_socket.sendall(data)
# Main proxy server loop
def proxy_server(proxy_host, proxy_port, target_host, target_port):
proxy_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
proxy_socket.bind((proxy_host, proxy_port))
proxy_socket.listen(5)
print(f"Proxy server is listening on {proxy_host}:{proxy_port}")
while True:
client_socket, addr = proxy_socket.accept()
client_ip = addr[0]
print(f"Accepted connection from {client_ip}:{addr[1]}")
# Start a new thread to handle the client
client_thread = threading.Thread(target=handle_client, args=(client_socket, client_ip, target_host, target_port))
client_thread.start()
# Handle client requests
def handle_client(client_socket, client_ip, target_host, target_port):
# Connect to the target server
target_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
target_socket.connect((target_host, target_port))
# Forward client IP to the target server
target_socket.sendall(client_ip.encode())
# Forward traffic between client and target server
client_to_target_thread = threading.Thread(target=forward_traffic, args=(client_socket, target_socket))
target_to_client_thread = threading.Thread(target=forward_traffic, args=(target_socket, client_socket))
client_to_target_thread.start()
target_to_client_thread.start()
# Wait for the threads to complete
client_to_target_thread.join()
target_to_client_thread.join()
# Close the sockets
client_socket.close()
target_socket.close()
# Start the proxy servers
def start_proxy_servers():
# Start login-server proxy
login_server_thread = threading.Thread(target=proxy_server, args=(LOGIN_SERVER_PROXY_HOST, LOGIN_SERVER_PROXY_PORT, LOGIN_SERVER_TARGET_HOST, LOGIN_SERVER_TARGET_PORT))
login_server_thread.start()
# Start char-server proxy
char_server_thread = threading.Thread(target=proxy_server, args=(CHAR_SERVER_PROXY_HOST, CHAR_SERVER_PROXY_PORT, CHAR_SERVER_TARGET_HOST, CHAR_SERVER_TARGET_PORT))
char_server_thread.start()
# Start map-server proxy
map_server_thread = threading.Thread(target=proxy_server, args=(MAP_SERVER_PROXY_HOST, MAP_SERVER_PROXY_PORT, MAP_SERVER_TARGET_HOST, MAP_SERVER_TARGET_PORT