-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdummy_test.py
More file actions
56 lines (45 loc) · 1.48 KB
/
dummy_test.py
File metadata and controls
56 lines (45 loc) · 1.48 KB
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
from scapy.all import *
import test_dsm as dsm
import of_side_effect as OF
import sys
import threading
pkts = sniff(offline="./example_packets/example_packets2.pcap")
pkt = pkts[0]
# Pretend the pkt is originally a POX packet converted to bytes.
pkt_bytes = str(pkt)
# Convert the raw bytes to a new packet compatible with Scapy.
pkt = Ether(pkt_bytes)
engine = dsm.Engine()
starting_of_rules = engine.get_initial_rules()
print "List of starting rules: "
for rule in starting_of_rules:
print str(rule)
def invoke_with_packet_or_timeout(pkt, timeout=0):
ret_list = []
if pkt:
ret_list = engine.handle_packet(pkt)
else:
ret_list = engine.handle_packet(None, timeout)
if ret_list[0] == "Exit":
print "DSM Complete!"
sys.exit(0)
if ret_list[0] == True:
print "We matched a packet!"
else:
print "Nothing matched..."
if len(ret_list) > 1:
print "OF rules to apply: " + str(ret_list[1:])
invoke_with_packet_or_timeout(pkt)
invoke_with_packet_or_timeout(None, 100)
invoke_with_packet_or_timeout(pkt)
invoke_with_packet_or_timeout(None, 100)
invoke_with_packet_or_timeout(pkt)
invoke_with_packet_or_timeout(None, 100)
invoke_with_packet_or_timeout(pkt)
invoke_with_packet_or_timeout(None, 100)
invoke_with_packet_or_timeout(pkt)
invoke_with_packet_or_timeout(None, 100)
invoke_with_packet_or_timeout(pkt)
invoke_with_packet_or_timeout(None, 100)
invoke_with_packet_or_timeout(pkt)
invoke_with_packet_or_timeout(None, 100)