-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscan.py
More file actions
43 lines (34 loc) · 1.26 KB
/
scan.py
File metadata and controls
43 lines (34 loc) · 1.26 KB
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
import argparse
import requests
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("--api-key", required=True)
parser.add_argument("--target-id", required=True)
parser.add_argument("--region", required=True)
parser.add_argument("--scan-profile", required=True)
namespace = parser.parse_args()
return (
namespace.api_key,
namespace.target_id,
namespace.region,
namespace.scan_profile,
)
def scan(api_key: str, target_id: str, base_url: str, scan_profile: str):
response = requests.post(
f"{base_url}/targets/{target_id}/scan_now/",
json={"scan_profile": scan_profile} if scan_profile else {},
headers={"Authorization": f"JWT {api_key}"},
)
try:
response.raise_for_status()
except requests.HTTPError:
print("Received error from Probely's API when starting the scan:")
print(f"Status code: {response.status_code}")
print(f"Content: {response.content.decode()}")
exit(1)
else:
print("Scan started successfully.")
if __name__ == "__main__":
api_key, target_id, region, scan_profile = parse_args()
base_url = f"https://api.{region}.probely.com"
scan(api_key, target_id, base_url, scan_profile)