-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathlist_iocs.py
33 lines (30 loc) · 1008 Bytes
/
list_iocs.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
import re
from load_pattern import load_patterns,path
from nltk import sent_tokenize
class iocs:
def find_them_all(self):
lst = []
pat = load_patterns(path)
for key, value in pat.items():
files = re.findall(value, self)
if files:
lst.append(files)
return lst
def list_of_iocs(self):
ioc_list = []
sentences = sent_tokenize(self)
for i in sentences:
x = iocs.find_them_all(i)
for i in range(len(x)):
for ioc in x[i]:
if len(x[i]) == 1:
if type(x[i][0]) == tuple:
ioc_list.append(x[i][0][0])
break
if len(x[i]) > 1:
if type(x[i][0]) == tuple:
for k in x[i]:
ioc_list.append(k[0])
else:
ioc_list.append(x[i][0])
return ioc_list