-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshell.py
28 lines (26 loc) · 867 Bytes
/
shell.py
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
#!/usr/bin/env python
import asyncio
import websockets
PROMPT="JS> "
HOST="0.0.0.0"
PORT=31337
async def shell(websocket, path):
print("Client connected " + websocket.remote_address[0], flush=True)
while True:
# Currently, in case of multiple connections, just hit empty command
# and it would break of out this loop and prompt for next connection
cmd = input(PROMPT)
if (cmd == ''):
print("Disconnected")
print("Waiting for client...", flush=True)
break
await websocket.send(cmd)
print("Starting on "+HOST+":"+repr(PORT))
start_server = websockets.serve(shell, HOST, PORT)
print("Waiting for client...", flush=True)
try:
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
except KeyboardInterrupt:
print("Bye")
quit()