Created
November 13, 2018 19:48
-
-
Save jfrantz1-r7/47ae95677ae08632513ac37f69dacdd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
import urllib3 | |
import time | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
url = "https://<address here>/api/3/sites" | |
payload = {"description":"Ad-Hoc scanning site, will be deleted after an asset is scanned","engineId":"<id of engine>","name":"<scan name>","scan":{"assets":{"includedTargets":{"addresses":["<ip address>"]}}},"scanTemplateId":"<template-name>"} | |
headers = { | |
'Content-Type': "application/json", | |
'Authorization': "Basic base64credentials", | |
'cache-control': "no-cache", | |
} | |
response = requests.request("POST", url, data=json.dumps(payload), headers=headers, verify=False) | |
if response.status_code != 201: | |
print("Error %d when creating site. Please make sure this name doesn't exist!" % response.status_code) | |
else: | |
siteresponse = json.loads(response.text) | |
siteid = siteresponse["id"] | |
url = "https://<address here>/api/3/sites/%d/scans" % siteid | |
payload = {"name":"IpAddressOfAsset"} | |
response = requests.request("POST", url, data=json.dumps(payload), headers=headers, verify=False) | |
if response.status_code != 201: | |
print("Error %d when trying to kick off the scan" % response.status_code) | |
else: | |
scanresponse = json.loads(response.text) | |
scanid = scanresponse["id"] | |
url = "https://<address here>/api/3/scans/%d" % scanid | |
response = requests.request("GET", url, headers=headers, verify=False) | |
if response.status_code != 200: | |
print("Error %d when trying to get the scan status!" % response.status_code) | |
else: | |
scanstatus = json.loads(response.text) | |
while scanstatus["status"] == "running": | |
response = requests.request("GET", url, headers=headers, verify=False) | |
scanstatus = json.loads(response.text) | |
print(scanstatus) | |
time.sleep(60) | |
url = "https://<address here>/api/3/sites/%d" % siteid | |
response = requests.request("DELETE", url, headers=headers, verify=False) | |
print(response.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment