-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.py
executable file
·77 lines (58 loc) · 1.68 KB
/
checker.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
#!/usr/bin/env python3
import argparse
import os
import shutil
import sys
import traceback
from scapy.sendrecv import sendp, sniff
import info
import tests
def capture(interface, output_file="test"):
cap = sniff(iface=interface, timeout=info.TIMEOUT - 2)
# FIXME
packets = []
for i in range(len(cap)):
packets.append(cap[i])
return packets
def passive(host, testname):
iface = info.get("host_if_name", host)
packets = capture(iface)
test = tests.TESTS[testname]
if host == test.host_r:
fn = test.passive_fn
elif host == test.host_s:
fn = tests.sender_default
else:
fn = tests.check_nothing
try:
status = fn(testname, packets)
except AssertionError as e:
traceback.print_tb(e.__traceback__)
status = False
if (status):
print("PASS")
else:
print("FAIL")
def send_packets(packets, iface):
for packet in packets:
sendp(packet, iface=iface)
def active(host, testname):
test = tests.TESTS[testname]
iface = info.get("host_if_name", host)
packets = test.active_fn(testname)
send_packets(packets, iface)
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--passive", action="store_true")
parser.add_argument("--active", action="store_true")
parser.add_argument("--testname", type=str)
# Technically we *could* determine this, but this is simpler
parser.add_argument("--host", type=int)
args = parser.parse_args()
assert(args.passive ^ args.active)
if args.passive:
passive(args.host, args.testname)
else:
active(args.host, args.testname)
if __name__ == "__main__":
main()