Repository navigation
Expand file tree
/
Copy pathclient_cli.py
More file actions
66 lines (57 loc) · 1.62 KB
/
Copy pathclient_cli.py
File metadata and controls
66 lines (57 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from exposehost.client import Client
import asyncio
import sys
import getpass
from time import sleep
from exposehost.shell import interactive_shell
proto = 'http' # Default to HTTP
auth_enabled = False
auth_users = {}
if len(sys.argv) > 1:
if sys.argv[1] == 'tcp':
proto = 'tcp'
elif sys.argv[1] == 'auth':
# Auth mode - stays HTTP but enables authentication
auth_enabled = True
user = input("Auth Username: ")
password = getpass.getpass("Auth Password: ")
auth_users[user] = password
port = input("Port to forward: ")
subdomain = input("Subdomain: ")
client = Client(
'127.0.0.1',
int(port),
"exposehost.me",
1435,
proto,
subdomain,
auth_enabled=auth_enabled,
auth_users=auth_users
)
# Start server without blocking (returns a Future for connection task)
task = client.start_non_blocking()
print("Tunnel starting...")
# Check server connection status
print(f"Status: {client.get_status()}")
sleep(2)
# Check status after 2s (enough for successful connection), print URL
print(f"Status: {client.get_status()}")
print(f"URL: {client.get_url()}")
if auth_enabled:
# Submit the interactive shell coroutine to the client's running loop
shell_future = asyncio.run_coroutine_threadsafe(
interactive_shell(client),
client.loop
)
# Block main thread until shell exits (user types 'exit')
try:
shell_future.result()
except KeyboardInterrupt:
pass
else:
# Standard blocking mode
# Wait for the background connection task
try:
task.result()
except KeyboardInterrupt:
pass