-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.py
64 lines (59 loc) · 1.32 KB
/
example.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
import nflog
import select
def nfprint(
indev,
outdev,
ifname,
proto,
payload_len,
payload,
hwll_hdr_len,
hwll_hdr
):
print('Interface: {}'.format(ifname))
print("Ethertype: 0x{:04x}".format(proto))
print('Hw Hdr size: {}'.format(hwll_hdr_len))
print('Hw Hdr:')
i = 0
end = ' '
for c in hwll_hdr:
if i < 7 or (i > 7 and i < 15):
end = ' '
i = i + 1
elif i == 15:
end = '\n'
i = 0
else:
end = ' '
i = i + 1
print("{:02x}".format(int(c)), end=end)
print()
print('Pkt size: {}'.format(payload_len))
print('Pkt:')
i = 0
end = ' '
for c in payload:
if i < 7 or (i > 7 and i < 15):
end = ' '
i = i + 1
elif i == 15:
end = '\n'
i = 0
else:
end = ' '
i = i + 1
print("{:02x}".format(int(c)), end=end)
print('\n')
nflog.setgroup(1)
nflog.setcb(nfprint)
nflog.start()
timeout = 5000
fd = nflog.getfd()
poll_handle = select.poll()
poll_handle.register(fd, select.POLLIN)
import time
t0 = time.time()
while time.time() < (t0 + 600):
plist = poll_handle.poll(timeout)
if len(plist) > 0:
nflog.handle()