-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstart_scan_all_targets.py
executable file
·49 lines (38 loc) · 1.58 KB
/
start_scan_all_targets.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
#!/usr/bin/env python
import requests
from urllib.parse import urljoin
def main():
token = input("API Token:")
headers = {"Authorization": "JWT {}".format(token)}
api_base_url = "https://api.probely.com"
targets_endpoint = urljoin(
api_base_url, "targets/?include=compliance&length=10000"
)
response = requests.get(targets_endpoint, headers=headers)
results = None
try:
results = response.json()["results"]
except:
print('Failed getting the list of targets, confirm if the API Token is correct.')
return
for result in results:
target_id = result.get("id", None)
if target_id is not None:
target_name = result["site"]["name"]
target_url = result["site"]["url"]
scan_now_endpoint = urljoin(api_base_url, "targets/{target_id}/scan_now/")
try:
scan_response = requests.post(scan_now_endpoint.format(target_id=target_id),
headers=headers)
scan_result = scan_response.json()
if "error" in scan_result:
error = scan_result["error"]
print(f"Error: {error} => ({target_name}) {target_url}")
elif "id" not in scan_result:
print(f"Error: Starting scan on ({target_name}) {target_url} failed")
else:
print(f"Started scan on ({target_name}) {target_url}")
except:
print(f"Failed starting scan on ({target_name}) {target_url}")
if __name__ == '__main__':
main()