#!/usr/bin/python from __future__ import print_function import datetime import socket import random, string def myrandom(length): return ''.join(random.choice(string.lowercase) for i in range(length)) if __name__ == '__main__': TCP_IP = '::' TCP_PORT = 1337 BUFFER_SIZE = 1024 s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) s.bind((TCP_IP, TCP_PORT)) s.listen(1) while 1: conn, addr = s.accept() report_id = myrandom(10) filename = 'reports/' + datetime.date.today().strftime('%Y-%m-%d_') + report_id + '.gz' f = open(filename, 'w') while 1: data = conn.recv(BUFFER_SIZE) if not data: break if data is "ende": break f.write(data) # python will convert \n to os.linesep f.flush() f.close() # send reply to reportee conn.send(report_id) conn.close() print 'new report:', filename pass