Skip to content

Commit c8e59de

Browse files
authored
Merge pull request #10 from suskind/start_scan_all_targets
script to start a scan in all existing targets
2 parents cc49b1b + 5b19985 commit c8e59de

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

start_scan_all_targets.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
3+
import requests
4+
from urllib.parse import urljoin
5+
6+
def main():
7+
token = input("API Token:")
8+
9+
headers = {"Authorization": "JWT {}".format(token)}
10+
11+
api_base_url = "https://api.probely.com"
12+
targets_endpoint = urljoin(
13+
api_base_url, "targets/?include=compliance&length=10000"
14+
)
15+
16+
response = requests.get(targets_endpoint, headers=headers)
17+
results = None
18+
try:
19+
results = response.json()["results"]
20+
except:
21+
print('Failed getting the list of targets, confirm if the API Token is correct.')
22+
return
23+
24+
for result in results:
25+
target_id = result.get("id", None)
26+
if target_id is not None:
27+
target_name = result["site"]["name"]
28+
target_url = result["site"]["url"]
29+
30+
scan_now_endpoint = urljoin(api_base_url, "targets/{target_id}/scan_now/")
31+
32+
try:
33+
scan_response = requests.post(scan_now_endpoint.format(target_id=target_id),
34+
headers=headers)
35+
scan_result = scan_response.json()
36+
37+
if "error" in scan_result:
38+
error = scan_result["error"]
39+
print(f"Error: {error} => ({target_name}) {target_url}")
40+
elif "id" not in scan_result:
41+
print(f"Error: Starting scan on ({target_name}) {target_url} failed")
42+
else:
43+
print(f"Started scan on ({target_name}) {target_url}")
44+
except:
45+
print(f"Failed starting scan on ({target_name}) {target_url}")
46+
47+
48+
if __name__ == '__main__':
49+
main()

0 commit comments

Comments
 (0)