Skip to content

Commit cc55a3b

Browse files
authored
Create MainAPI.py
0 parents  commit cc55a3b

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

MainAPI.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import requests
2+
from requests.auth import HTTPBasicAuth
3+
# For in house hosted API
4+
# Replace these values with your SecurityCenter information
5+
Tenable_SERVER = 'https://your-securitycenter-server'
6+
ACCESS_KEY = 'your-access-key'
7+
SECRET_KEY = 'your-secret-key'
8+
SCAN_ID = 1 # Replace with the ID of the scan you want to initiate
9+
10+
# API endpoint for initiating a scan
11+
SCAN_ENDPOINT = f'{Tenable_SERVER}/rest/scan/{SCAN_ID}/launch'
12+
13+
# Set up the headers and authentication
14+
headers = {
15+
'Content-Type': 'application/json',
16+
'Accept': 'application/json',
17+
}
18+
auth = HTTPBasicAuth(ACCESS_KEY, SECRET_KEY)
19+
20+
# Initiate the scan
21+
try:
22+
response = requests.post(SCAN_ENDPOINT, headers=headers, auth=auth, verify=False)
23+
response.raise_for_status()
24+
print(f'Scan initiation successful. Response: {response.text}')
25+
except requests.exceptions.HTTPError as err:
26+
print(f'Error initiating scan: {err}')
27+
except Exception as e:
28+
print(f'An error occurred: {e}')

0 commit comments

Comments
 (0)