-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
37 lines (26 loc) · 897 Bytes
/
server.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
35
36
37
import socket
from config import CONNECTION, read_data
from commands import commands
FORMAT = "utf-8"
def server_program():
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(CONNECTION)
server_socket.listen(5)
conn, address = server_socket.accept()
print("Connection from: " + str(address))
while True:
data = read_data(conn).decode().strip()
if not data:
break
print("received: " + data)
command = data.split(" ")[0]
if command in commands:
response = commands[command]
elif "list" in data:
response = "pwd, ls, cd, nmap, netdiscover, rm, cp, mkdir, mv, dirb"
else:
response = "Command not found"
conn.sendall(response.encode(FORMAT) + b"\r\n\r\n")
conn.close()
if __name__ == "__main__":
server_program()