-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_csr_interfaces_restconf.py
More file actions
38 lines (31 loc) · 1.03 KB
/
get_csr_interfaces_restconf.py
File metadata and controls
38 lines (31 loc) · 1.03 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
import requests
from requests.auth import HTTPBasicAuth
import urllib3
import json
# Disable SSL warning for self-signed certs (use with caution in production)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# --- Configuration ---
router_ip = "devnetsandboxiosxe.cisco.com" # Replace with your CSR IP
username = "admin"
password = "C1sco12345"
# RESTCONF URL to get interface data
url = f"https://devnetsandboxiosxe.cisco.com/restconf/data/ietf-interfaces:interfaces"
# Headers for RESTCONF
headers = {
"Accept": "application/yang-data+json",
"Content-Type": "application/yang-data+json"
}
# --- Make the GET request ---
response = requests.get(
url,
auth=HTTPBasicAuth(username, password),
headers=headers,
verify=False # Disable SSL verification for testing
)
# --- Check response ---
if response.status_code == 200:
interfaces = response.json()
print(json.dumps(interfaces, indent=2))
else:
print(f"Request failed with status code {response.status_code}")
print(response.text)