-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.py
46 lines (36 loc) · 976 Bytes
/
tools.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
import time
import functools
import os
from scapy import *
def log_time(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
start_time = time.time()
result = func(*args, **kwargs)
end_time = time.time()
print("Time: %f " % (end_time - start_time))
return result
return wrapper
def merge():
path = 'data/abnormal'
filename = 'output/all.pcap'
fs = os.listdir(path)
fs = [os.path.join(path, f) for f in fs if f.find('pcap') != -1]
writer = PcapWriter(filename)
for f in fs:
try:
s = PcapReader(f)
while True:
try:
p = s.read_packet()
writer.write(p)
except EOFError:
break
s.close()
writer.flush()
except Exception as e:
print('Error', e)
writer.flush()
writer.close()
if __name__ == "__main__":
merge()