-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscountwireshark.py
77 lines (62 loc) · 1.33 KB
/
discountwireshark.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
76
77
"""
ORIGINAL PYTHON SCRIPT WRITTEN
Kept for posterity sake
"""
import sys
def printRawData(tabTrames):
cpt=0
for trame in tabTrames :
if(trame == ""):
return
print("Trame "+str(cpt))
cpt+=1
print(trame)
# Lit l'entete ETHERNET
# Recoit une sequence d'octets
def readEthernet(trame) :
tabEthernet= []
tabEthernet.append(trame[0:12])
tabEthernet.append(trame[12:24])
tabEthernet.append(trame[24:28])
return tabEthernet
def printMacAddress(tempMac, origin):
res = "("
i = 1
for letter in tempMac :
res+=letter
if i%2 == 0 :
res+=":"
i+=1
res = res.rstrip(res[-1])
res+=")"
print("Addresse MAC "+origin+" = "+res)
def getInput(filename) :
f = open(filename, 'r')
# Ethernet reader
tabTrames = []
nTrame = -1
rawInput = ""
for line in f :
offset = line[0:4]
if (offset == "0000") :
nTrame+=1
tabTrames.append("")
line = line.lstrip(offset)
line = line.replace("\n", "")
line = line.replace(" ", "")
rawInput += line
tabTrames[nTrame]+=line
f.close
return tabTrames
def main() :
if sys.argv[1] == 0 :
print ("usage: python3 discountwireshark.py <nom_du_fichier>")
return
filename = sys.argv[1]
tabTrames = getInput(filename)
#test
printRawData(tabTrames)
enteteEthernet = readEthernet(tabTrames[1])
printMacAddress(enteteEthernet[0], "dest")
if __name__ == "__main__":
main()