-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver80.py
More file actions
35 lines (29 loc) · 1.04 KB
/
Copy pathserver80.py
File metadata and controls
35 lines (29 loc) · 1.04 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
import socket
import datetime
HOST = '0.0.0.0' # Symbolic name meaning all available interfaces
PORT = 80 # Arbitrary non-privileged port
sock_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_server.bind((HOST, PORT))
sock_server.listen(5)
def connect():
conn, addr = sock_server.accept()
conn.settimeout(3)
try:
with conn:
print('Connected by', addr)
while True:
data = conn.recv(1024)
if not data: break
file_path = './data/' + str(addr[0]) + '.bin'
with open(file_path, "ab") as fo:
fo.write(bytes(str(datetime.datetime.now())+' port: 80\n','utf-8'))
fo.write(data)
fo.write(bytes('\n\n','utf-8'))
conn.sendall(b"<error>Unknown error</error>")
break
except Exception as e:
print(e)
print("done.")
if __name__ == "__main__":
while True:
connect()