-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
43 lines (39 loc) · 942 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
38
39
40
41
42
43
import socket
import os
import time
port = 52918
conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conn.bind(('0.0.0.0', port))
conn.listen(1)
while 1:
try:
os.system("clear")
print('[*] Listening for upcoming connections...')
client_conn , info = conn.accept()
print('[+] New client found from ip ' + str(info[0]) + ' !')
try:
msg = b''
while msg != 'end':
try:
msg = raw_input(str(info[0]) + ' > ')
if(msg == b''):
pass
else:
msg = msg.encode()
client_conn.send(msg)
recv = client_conn.recv(1024*3)
recv = recv.decode()
print(recv)
except BrokenPipeError:
print('[-] Client disconnected...')
break
except KeyboardInterrupt:
print('\n[-] Session Closed')
msg = 'end'
msg = msg.encode()
client_conn.send(msg)
client_conn.close()
time.sleep(2)
except KeyboardInterrupt:
print('\n[-] Shutting down the server...')
break