-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
35 lines (27 loc) · 1.04 KB
/
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
import socket
from datetime import datetime
def server(host='0.0.0.0', port=2000):
# create socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.bind((host, port))
# sock.setblocking(False)
print("[+] Listening on {0}:{1}".format(host, port))
sock.listen(5)
# permit to access
connect, addr = sock.accept()
with connect as conn:
# display the current time
time = datetime.now().ctime()
print("[+] Connecting by {0}:{1} ({2})".format(
addr[0], addr[1], time))
while True:
request = conn.recv(4096)
print("[+] Received", repr(request.decode('utf-8')))
response = input("[+] Enter string : ")
conn.sendall(response.encode('utf-8'))
print("[+] Sending to {0}:{1}".format(addr[0], addr[1]))
if not request:
print("[-] Not Received")
break
if __name__ == "__main__":
server()