-
Notifications
You must be signed in to change notification settings - Fork 6
/
safebrowsing.py
67 lines (47 loc) · 1.78 KB
/
safebrowsing.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
66
67
import requests
import json
SB_CLIENT_ID = "Python Safebrowsing"
SB_CLIENT_VER = "1.0.0"
class SafebrowsingLookup(object):
def __init__(self, apikey):
self.apiurl = 'https://safebrowsing.googleapis.com/v4/threatMatches:find?key=%s' % (apikey)
self.platform_types = ['ANY_PLATFORM']
self.threat_types = ['THREAT_TYPE_UNSPECIFIED',
'MALWARE',
'SOCIAL_ENGINEERING',
'UNWANTED_SOFTWARE',
'POTENTIALLY_HARMFUL_APPLICATION']
self.threat_entry_types = ['URL']
def set_threat_types(self, threats):
self.threat_types = threats
def set_platform_types(self, platforms):
self.platform_types = platforms
def threat_matches_find(self, *urls):
threat_matches = []
results = {}
for url_ in urls:
url = {'url': url_}
threat_matches.append(url)
request= {
'client': {
'clientId': SB_CLIENT_ID,
'clientVersion': SB_CLIENT_VER
},
'threatInfo': {
'threatTypes': self.threat_types,
'platformTypes': self.platform_types,
'threatEntryTypes': self.threat_entry_types,
'threatEntries': threat_matches
}
}
try:
headers = {'Content-Type': 'application/json'}
r = requests.post(self.apiurl,
data=json.dumps(request),
headers=headers)
return r.json()
except requests.exceptions.RequestException as e:
print(e)
class UpdateAPI(object):
def __init__(self, apikey):
pass