-
Notifications
You must be signed in to change notification settings - Fork 1
/
grab_time_interval.py
52 lines (45 loc) · 1.89 KB
/
grab_time_interval.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
# Author: Chenfeng Nie
import os
import re
import glob
#path = glob.glob('/Users/levonnie/Desktop/CIP_Result/10vs10/output/*')
###########################
# Malware:
# #/Users/levonpro/Desktop/CIP/Output_Malware_Apps/*
# Non-Malware:
# #/Users/levonpro/Desktop/CIP/Output_Non_Malware_Apps/*
#########################
path = glob.glob('/Users/levonpro/Desktop/CIP/Output_Non_Malware_Apps/*')
for folder in path:
name = folder + '/*.txt'
txtfile = (glob.glob(name))
#print(txtfile)
for filename in sorted(txtfile):
#print(filename)
#open the "data.txt" (named data_file in a scope)
with open(filename) as data_file:
#read the text from the data_file into ping_data
#ping_data = data_file.read()
#found_data = re.findall('time=(.*)ms', ping_data)
processed_data = []
for ping_data in data_file:
#replace timeout with 500.000 ms
if "Request timeout for icmp_seq" in ping_data:
processed_data.append('500.000')
elif 'time=' in ping_data:
find_ping = re.findall('time=(.*)ms', ping_data)
processed_data.append(find_ping)
#print(processed_data)
data_file.close()
# grab filename in each txt file
i = filename.split('/')[-1].split('.txt')[0]
#print(i)
#print("the number is: " + i )
with open(folder + "/Processed_%s.csv" % i, "w") as found_file:
for pattern in processed_data:
string = str(pattern).replace("['", '')
new_string = str(string).replace("']", '')
#print(new_string)
found_file.write(new_string + '\n')
print("Writing : " + "Processed_%s.csv" % i + " in " + folder)