12-22-2022 01:56 PM
Hello,
I'm new to network programmability. I am wondering is there a module that can provide the information same as "show ip interface brief" meaning interface names and ip addresses. The module I have been referencing to provides unwanted detail:
Cisco-IOS-XE-interfaces-oper:interfaces
Thanks,
Qamber
12-22-2022 08:21 PM
you can use python if that work for you ?
12-22-2022 11:48 PM
Try
# import requests, jason and sys
import requests
import json
import sys
#device details
HOST = 'ios-xe-mgmt-latest.cisco.com'
PORT = 443
USER = 'developer'
PASS = 'C1sco12345'
# disable urlib3 warning
requests.packages.urllib3.disable_warnings()
#main function using restconf to show the status of device interface and print results in json
def main():
# create a main function using restconf
url = "https://{}:{}@{}:{}/restconf/data/ietf-interfaces:interfaces".format(USER, PASS, HOST, PORT)
headers = {'Content-Type': 'application/yang-data+json'}
response = requests.get(url, headers=headers, verify=False)
print(response.status_code)
# print the results in json format
print(json.dumps(response.json(), indent=4))
# Call the function main() and exit giving the system the return code that is the result of main()
if __name__ == '__main__':
sys.exit(main())
Will print the following
❯ {
∙ "ietf-interfaces:interfaces": {
∙ "interface": [
∙ {
∙ "name": "GigabitEthernet1",
∙ "description": "MANAGEMENT INTERFACE - DON'T TOUCH ME",
∙ "type": "iana-if-type:ethernetCsmacd",
∙ "enabled": true,
∙ "ietf-ip:ipv4": {
∙ "address": [
∙ {
∙ "ip": "10.10.20.48",
∙ "netmask": "255.255.255.0"
∙ }
∙ ]
∙ }
[snip]
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide