-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·85 lines (71 loc) · 2.4 KB
/
test.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
78
79
80
81
82
83
84
85
"""
Performs benchmarking for the current version
"""
import os
import sys
sys.path.append(os.path.abspath("./scapy"))
sys.path.append(os.path.abspath("./scapy/scapy"))
sys.path.append(os.path.abspath("./scapy/scapy/layers"))
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
logging.getLogger("scapy").setLevel(logging.ERROR)
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
from scapy.all import *
import importlib
import os
# DEFINE TESTS
import time
raw_packet = b'E\x00\x00(\x00\x01\x00\x00@\x11|\xc2\x7f\x00\x00\x01\x7f\x00\x00\x01\x005\x005\x00\x14\x00Z\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00'
def test_dissect(N=5000):
a = time.time()
for i in range(N):
IP(raw_packet)
delta = time.time() - a
return delta / N * 1000
import time
def test_build(N=5000):
a = time.time()
for i in range(N):
bytes(IP(version=4, ihl=5, tos=0, len=40, id=1, flags=0, frag=0, ttl=64, proto=17, chksum=31938, src='127.0.0.1', dst='127.0.0.1')/UDP(sport=53, dport=53, len=20, chksum=90)/DNS())
delta = time.time() - a
return delta / N * 1000
def nb_layers():
lay_default = len(conf.layers)
# Load contribs
def _load(ty):
lay_init = len(conf.layers)
nb_ok = 0
nb_broken = 0
for fname in os.listdir("scapy/scapy/%s" % ty):
# We dont want to include automaton or scada
# (too many "fake" layers)
if fname.endswith('.py'):
try:
if fname in sys.argv:
raise Exception
importlib.import_module(
"scapy.%s.%s" % (ty, fname[:-3])
)
nb_ok += 1
except Exception:
nb_broken += 1
return (len(conf.layers) - lay_init), nb_ok, nb_broken
lay_lay, nb_lay_ok, nb_lay_broken = _load("layers")
lay_contrib, nb_contrib_ok, nb_contrib_broken = _load("contrib")
nb_contrib_ok += nb_lay_ok
nb_contrib_broken += nb_lay_broken
return ",".join(str(x) for x in [
lay_default, lay_lay, lay_contrib,
nb_contrib_ok, nb_contrib_broken
])
# RUN TESTS
N = 20000
import warnings
with warnings.catch_warnings():
warnings.simplefilter("ignore")
a = test_build(N)
b = test_dissect(N)
c = nb_layers()
print("%s:%s:%s" % (a, b, c))