-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAMESHSELVAM_KIRTHANA_hw5_localscrape.py
65 lines (59 loc) · 2.22 KB
/
RAMESHSELVAM_KIRTHANA_hw5_localscrape.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
53
54
55
56
57
58
59
60
61
62
63
64
65
from bs4 import BeautifulSoup
import requests
import pandas as pd
import sqlite3
import json
import gmplot
import RAMESHSELVAM_KIRTHANA_hw5_plot
import sys
import operator
#this function will display the top 5 most occuring/detected malware
def findmaxmaltype():
conn = sqlite3.connect('projectMal.db')
query = 'select "Type_of_Malware" from "Malwaredata"'
df = pd.read_sql(query,conn)
c = 1
count = dict()
for i in df["Type_of_Malware"]:
if str.isalpha(i[0]):
if i not in count:
count[i] = 1
else:
count[i] += 1
print("Statistics: \nThe 5 most common types of Malware are:")
count = sorted(count.items(), key=operator.itemgetter(1), reverse = True)
df2 = pd.DataFrame(count,columns={'Number of Occurances','Type of Malware'})
print(df2.head(5))
#this function will display the malware that has been reported with the most number of indicators of compromise
def findmaxioc():
conn = sqlite3.connect('projectMal.db')
query = 'select "ioc" from "Locationdata"'
df = pd.read_sql(query,conn)
print("\nMaximum number of indicators of compromise are from :")
maxi = max(df["ioc"])
print("IOCs:",maxi)
query = 'select "ip","country" from "Locationdata" where "ioc"='+str(maxi)
df2 = pd.read_sql(query,conn)
print("IP address of malware:",str(df2["ip"]).split()[1])
que = "select Type_of_Malware from Malwaredata,Locationdata where Malwaredata.IP_Address=Locationdata.ip AND Locationdata.ioc="+"'"+str(maxi)+"'"
d = pd.read_sql(que,conn)
print("Type of Malware:",str(d["Type_of_Malware"]).split()[1])
print("Orginiating country:",str(df2["country"]).split()[1])
#this function will compute the top 5 countries that produces the most number of malware
def findmaxcountry():
conn = sqlite3.connect('projectMal.db')
query = 'select "country" from "Locationdata"'
df = pd.read_sql(query,conn)
count = dict()
for i in df["country"]:
if not i:
continue
if str.isalpha(i[0]):
if i not in count:
count[i] = 1
else:
count[i] += 1
print("\nThe top 5 threat producing countries are :")
count = sorted(count.items(), key=operator.itemgetter(1), reverse = True)
df2 = pd.DataFrame(count,columns={'Number of Malware','Country'})
print(df2.head(5))