-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwatcher.py
More file actions
54 lines (40 loc) · 1.39 KB
/
watcher.py
File metadata and controls
54 lines (40 loc) · 1.39 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
import os
import sys
from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer
from multiprocessing import Process
from main import analysis
class PcapHandler(FileSystemEventHandler):
analysis_process_list = list()
def __init__(self, observer):
self.observer = observer
def on_created(self, event):
if not event.is_directory: # and event.src_path.endswith(self.filename):
filename = os.path.basename(event.src_path)
print("%s created" % filename)
try:
filetype = filename.split('.')[-1]
except IndexError:
return
else:
if 'pcap' not in filetype:
return
print("Start Analysis %s" % filename)
# analysis(os.path.basename(event.src_path))
p = Process(target=analysis, args=(filename,))
p.start()
PcapHandler.analysis_process_list.append(p)
def main():
from config import project_path
path = project_path
observer = Observer()
event_handler = PcapHandler(observer)
observer.schedule(event_handler, path, recursive=False)
observer.start()
observer.join()
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
for analysis_process in PcapHandler.analysis_process_list:
analysis_process.join()