Redone formatting for logging

This commit is contained in:
Emily 2018-09-28 22:40:10 +02:00
parent 9af92cc75c
commit 3d1aa21bab

View File

@ -6,6 +6,11 @@ import select
class Proxy(Thread): class Proxy(Thread):
BUFF_SIZE = 65535 BUFF_SIZE = 65535
# Used to keep track of "lines"
prnt_id_client = 0
prnt_id_server = 0
def __init__(self, listen, target): def __init__(self, listen, target):
Thread.__init__(self) Thread.__init__(self)
self.listen = listen self.listen = listen
@ -43,15 +48,16 @@ class Proxy(Thread):
c_data = b"\x08\x1e\x77\xda" c_data = b"\x08\x1e\x77\xda"
""" """
print("[C] -> {}".format(c_data)) print("[C] -> {}".format(c_data))
with open("logs/{}-client-raw.log".format(LISTEN[1]), "ab") as f: with open("logs/{}-client-raw.log".format(LISTEN[1]), "a") as f:
f.write(c_data + b"\r\n") f.write("({}) {} \r\n".format(self.prnt_id_client, c_data))
with open("logs/{}-client-hex.log".format(LISTEN[1]), "a") as f: with open("logs/{}-client-hex.log".format(LISTEN[1]), "a") as f:
f.write(c_data.hex() + "\r\n") f.write("({}) {} \r\n".format(self.prnt_id_client, c_data.hex()))
with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f: with open("logs/{}-all-raw.log".format(LISTEN[1]), "a") as f:
f.write(b"[C] -> " + c_data + b"\r\n") f.write("[C] -> ({}) {} \r\n".format(self.prnt_id_client, c_data))
with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f: 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) target.sendto(c_data, self.target)
self.prnt_id_client += 1
(s, _, _) = select.select([target],[],[],0) (s, _, _) = select.select([target],[],[],0)
@ -60,15 +66,16 @@ class Proxy(Thread):
#print("[S] data:{}".format(s_data)) #print("[S] data:{}".format(s_data))
if s_data: if s_data:
print("[C] <- {}".format(s_data)) print("[C] <- {}".format(s_data))
with open("logs/{}-server-raw.log".format(LISTEN[1]), "ab") as f: with open("logs/{}-server-raw.log".format(LISTEN[1]), "a") as f:
f.write(s_data + b"\r\n") f.write("({}) {} \r\n".format(self.prnt_id_server, s_data))
with open("logs/{}-server-hex.log".format(LISTEN[1]), "a") as f: with open("logs/{}-server-hex.log".format(LISTEN[1]), "a") as f:
f.write(s_data.hex() + "\r\n") f.write("({}) {} \r\n".format(self.prnt_id_server, s_data.hex()))
with open("logs/{}-all-raw.log".format(LISTEN[1]), "ab") as f: with open("logs/{}-all-raw.log".format(LISTEN[1]), "a") as f:
f.write(b"[C] <- " + s_data + b"\r\n") f.write("[C] <- ({}) {} \r\n".format(self.prnt_id_server, s_data))
with open("logs/{}-all-hex.log".format(LISTEN[1]), "a") as f: 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) client.sendto(s_data, c_addr)
self.prnt_id_server += 1
client.close() client.close()
if len(sys.argv) < 4: if len(sys.argv) < 4: