forked from TrullJ/ssllabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssllabsscanner.py
60 lines (45 loc) · 1.49 KB
/
ssllabsscanner.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
#!/usr/bin/env python
import requests
import time
import sys
import logging
API = 'https://api.ssllabs.com/api/v2/'
def requestAPI(path, payload={}):
'''This is a helper method that takes the path to the relevant
API call and the user-defined payload and requests the
data/server test from Qualys SSL Labs.
Returns JSON formatted data'''
url = API + path
try:
response = requests.get(url, params=payload)
except requests.exception.RequestException:
logging.exception('Request failed.')
sys.exit(1)
data = response.json()
return data
def resultsFromCache(host, publish='off', startNew='off', fromCache='on', all='done'):
path = 'analyze'
payload = {
'host': host,
'publish': publish,
'startNew': startNew,
'fromCache': fromCache,
'all': all
}
data = requestAPI(path, payload)
return data
def newScan(host, publish='off', startNew='on', all='done', ignoreMismatch='on'):
path = 'analyze'
payload = {
'host': host,
'publish': publish,
'startNew': startNew,
'all': all,
'ignoreMismatch': ignoreMismatch
}
results = requestAPI(path, payload)
payload.pop('startNew')
while results['status'] != 'READY' and results['status'] != 'ERROR':
time.sleep(30)
results = requestAPI(path, payload)
return results