-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDRT2.py
More file actions
51 lines (43 loc) · 1.45 KB
/
DRT2.py
File metadata and controls
51 lines (43 loc) · 1.45 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
import csv
import datetime
import time
file_loc = input("Enter file directory: ")
file_name = input("Enter file name: ")
ips={}
bot_ips=[]
num_organized=0
print("organizing data")
t1=time.time()
with open(file_loc+"/"+file_name, encoding='utf-8') as csvfile:
file = csv.reader(csvfile)
for row in file:
ip=row[0]
if(ip!="ip"):
time_split = row[2].split(":")
total_seconds = datetime.timedelta(hours = int(time_split[0]), minutes = int(time_split[1]), seconds = int(time_split[2])).total_seconds()
if(ip in ips):
ips.get(ip).append(total_seconds)
else:
ips[ip]=[total_seconds]
num_organized+=1
if(num_organized%1000000==0):
print("organized "+str(num_organized) + " entries")
print("finished organizing " + str(num_organized)+ " entries. Now processing data")
print("there are "+str(len(ips))+ " unique IPS")
num_processed=0
for ip in ips:
times=ips.get(ip)
times_len=len(times)
if times_len>1000:
for i in range(times_len - 5):
if times[i+5]-times[i]<60:
bot_ips.append(ip)
break
num_processed+=1
if(num_processed%100000==0):
print("processed "+str(num_processed) +" IPs")
t2=time.time()
print("All bots:\n"+ str(bot_ips))
print("There are "+str(len(bot_ips))+ " bots")
print("Finished in "+str(t2-t1)+" seconds")
input("press any key to continue")