From 3d1aa21bab20aea1f06c679389c4367da9f0aae2 Mon Sep 17 00:00:00 2001 From: Sunpy Date: Fri, 28 Sep 2018 22:40:10 +0200 Subject: [PATCH] Redone formatting for logging --- proxy.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/proxy.py b/proxy.py index e23d057..cbf7eb0 100644 --- a/proxy.py +++ b/proxy.py @@ -6,6 +6,11 @@ import select class Proxy(Thread): BUFF_SIZE = 65535 + + # Used to keep track of "lines" + prnt_id_client = 0 + prnt_id_server = 0 + def __init__(self, listen, target): Thread.__init__(self) self.listen = listen @@ -43,15 +48,16 @@ class Proxy(Thread): c_data = b"\x08\x1e\x77\xda" """ print("[C] -> {}".format(c_data)) - with open("logs/{}-client-raw.log".format(LISTEN[1]), "ab") as f: - f.write(c_data + b"\r\n") + with open("logs/{}-client-raw.log".format(LISTEN[1]), "a") as f: + f.write("({}) {} \r\n".format(self.prnt_id_client, c_data)) with open("logs/{}-client-hex.log".format(LISTEN[1]), "a") as f: - f.write(c_data.hex() + "\r\n") - with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f: - f.write(b"[C] -> " + c_data + b"\r\n") + f.write("({}) {} \r\n".format(self.prnt_id_client, c_data.hex())) + with open("logs/{}-all-raw.log".format(LISTEN[1]), "a") as f: + f.write("[C] -> ({}) {} \r\n".format(self.prnt_id_client, c_data)) with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f: - f.write("[C] -> " + c_data.hex() + "\r\n") + f.write("[C] -> ({}) {} \r\n".format(self.prnt_id_client, c_data.hex())) target.sendto(c_data, self.target) + self.prnt_id_client += 1 (s, _, _) = select.select([target],[],[],0) @@ -60,15 +66,16 @@ class Proxy(Thread): #print("[S] data:{}".format(s_data)) if s_data: print("[C] <- {}".format(s_data)) - with open("logs/{}-server-raw.log".format(LISTEN[1]), "ab") as f: - f.write(s_data + b"\r\n") + with open("logs/{}-server-raw.log".format(LISTEN[1]), "a") as f: + f.write("({}) {} \r\n".format(self.prnt_id_server, s_data)) with open("logs/{}-server-hex.log".format(LISTEN[1]), "a") as f: - f.write(s_data.hex() + "\r\n") - with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f: - f.write(b"[C] <- " + s_data + b"\r\n") + f.write("({}) {} \r\n".format(self.prnt_id_server, s_data.hex())) + with open("logs/{}-all-raw.log".format(LISTEN[1]), "a") as f: + f.write("[C] <- ({}) {} \r\n".format(self.prnt_id_server, s_data)) with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f: - f.write("[C] <- " + s_data.hex() + "\r\n") + f.write("[C] <- ({}) {} \r\n".format(self.prnt_id_server, s_data.hex())) client.sendto(s_data, c_addr) + self.prnt_id_server += 1 client.close() if len(sys.argv) < 4: