You are on page 1of 3

LAB: Retrieving Interface Information from a Router using

NETCONF
In this lab, you will learn how to use the ncclient library in Python to establish an SSH connection to a network device,
retrieve interface information from the router's running configuration, and display the extracted data.

Step 1: Setting up the network device for configuration.

- Go to your eve-ng and add a Cisco CSR 1000V Routers and connect to Cloud 1 to establish communication
between PC and Router, make sure you modify the resources like shown below.

- Boot the router and provide IP to the management interface using DHCP.

enable
configure terminal
interface gig 1
ip address dhcp
no shutdown
exit

- Configure SSH on your router with the credentials: admin/cisco.

ip domain-name abc.com
cryptokey generate rsa general-keys modulus 1024
ip ssh ver 2
username admin privilege 15 password cisco
line vty 0 4
login local
transport input all
exit

- Enable Netconf on the Cisco Device.

netconf ssh
netconf-yang

- Verify the reachability by pinging the IP address of router from local device.

Step 2: Install the ncclient Library:

- Go to the terminal of your device using VS code or using cmd and run the following command to begin the
installation of the library ncclient:

python -m pip install ncclient


Step 3: Time to begin the script for creating the loopback interface on Router.

- The script begins by importing necessary modules, including manager from ncclient, getpass for securely
inputting the password, parseString from xml.dom.minidom for formatting XML, and parse from xmltodict for
converting XML to a dictionary.

- The script prompts the user to enter their username and password interactively.

- Create the R1 dictionary containing details about the network device you want to connect to, such as its IP
address, SSH port, username, password, and hostkey verification.

- Call the manager.connect module to connect with the router. (** before the dictionary name is used to tell the
python to consider the content of the dictionary as key-value pairs instead of single elements.)

- Create a int_filter variable containing the XML filter for retrieving interface information from the router's
running configuration.
- We will use the get_config method with the filter to retrieve interface information from the router's running
configuration.

- Now we will convert the output into dictionaries using xmltodict, and interface details are extracted and
displayed.

By completing this lab guide, you have gained hands-on experience in using the ncclient library to establish an SSH
connection to a network device, retrieve interface information from the router's running configuration, and display
the extracted data.

You might also like