-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethernetII.py
66 lines (62 loc) · 1.64 KB
/
ethernetII.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
import decimalToHex
import datashift
class EthernetII:
def __init__(self):
self.destination = 0
self.source = 0
self.type = 0
#Used to parse Ethernet II header
def ethernetIIParser(data, i):
destination = [0] * 6
source = [0] * 6
eth_type = [0] * 2
eth_type = hex(datashift.datashift(data, i+12, 2))
j = 0
k = 0
l = 0
while j < 14:
if(j < 6):
#print('if: ', data[i+j])
destination[j] = decimalToHex.decimalToHex(data[i + j])
#print('destination: ', destination[j])
elif(j < 12):
#print('elif: ', data[i+j])
source[k] = decimalToHex.decimalToHex(data[i+j])
#print('source: ', source[k])
k += 1
else:
#print('else: ', data[i+j])
#eth_type[l] = (decimalToHex.decimalToHex(data[i + j]))
#print('eth_type: ', eth_type[l])
l += 1
j += 1
#print('Destination: ', ':'.join(map(str, destination)))
#print('Source: ', ':'.join(map(str, source)))
#print('Type: ', eth_type)
#print('Type: ( 0x', ''.join(map(str, eth_type)), ')')
ethII = EthernetII()
ethII.destination = ':'.join(map(str, destination))
ethII.source = ':'.join(map(str, source))
ethII.type = eth_type
#ethII.type = ''.join(map(str, eth_type))
return ethII
# Test Case
data = [0] * 14
data[0] = 1
data[1] = 0
data[2] = 94
data[3] = 0
data[4] = 0
data[5] = 251
data[6] = 16
data[7] = 148
data[8] = 187
data[9] = 197
data[10] = 48
data[11] = 58
data[12] = 8
data[13] = 0
x = ethernetIIParser(data, 0);
#print(x.destination)
#print(x.source)
#print(x.type)