-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHTTP.py
75 lines (57 loc) · 2.27 KB
/
HTTP.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from Tools import *
class HTTP:
def __init__(self, trame, sizeTCP, overheadSize):
# string of hex
#self.rawHTTP = trame[sizeTCP + overheadSize:]
#self.rawASCII = 0
self.segment = trame[(sizeTCP+overheadSize):]
self.segmentDecoded = bytearray.fromhex(self.segment).decode()
lignes = self.segmentDecoded.split("\r\n")
self.lignesDeLEntete = []
self.lignesDuCorps = []
try:
indexOfEmpty = lignes.index("")
self.lignesDeLEntete, self.lignesDuCorps = (lignes[:indexOfEmpty], lignes[(indexOfEmpty+1):])
except:
print("ERROR!!!!")
for line in lignes:
print(line)
print(trame[(sizeTCP+overheadSize):(sizeTCP+overheadSize+20)])
try:
self.premiereLigne = self.lignesDeLEntete[0]
self.methode = self.premiereLigne.split(" ")[0]
self.URL = self.premiereLigne.split(" ")[1]
self.version = self.premiereLigne.split(" ")[2]
except:
self.methode = "?"
self.URL = "?"
self.version = "?"
try:
self.lignesDuCorpsTraduits = []
tmp = []
for ligne in self.lignesDeLEntete:
tmp = []
for champ in ligne.split(" "):
tmp.append(champ)
try:
self.lignesDuCorpsTraduits.append(f"FIELD: {tmp[0]} {tmp[1]}")
except:
self.lignesDuCorpsTraduits.append("FIELD: ?, VALUE: ?")
except:
self.lignesDuCorpsTraduits = []
def getInfo(self):
"""Generates a tab with all the HTTP info of the packet
Returns:
[str] : Each str represents a field of HTML
"""
res = []
res.append(self.methode)
res.append("VERSION: "+self.version)
res.append("URL: "+self.URL)
# res.append("\n")
if(self.lignesDuCorpsTraduits != []):
for line in self.lignesDuCorpsTraduits:
res.append(line)
return res
def getShortInfo(self):
return f"{self.version}:{self.methode}"