Network Automation : Get_facts to retrieve device information

Network Automation NAPALM (Python networking scripts examples)

In this network automation example, we will use the get_facts function to retrieve device information. This is a simple example of collecting information from a device. If you don’t have a network setup for practice, try using routers from Sandbox. Some routers are available 24×7. It doesn’t require you to activate the lab. Search for labs that have an “Always on” tab on them. Once you open this lab, you will see the design part on the right side and details such as IP address, username, and password on the left side.

We will connect to a Cisco router which is hosted in the sandbox with the following details

IP Address :
Username : developer
Password: C1sco12345

We will import get_network_driver from the Napalm library and also the JSON library.

from napalm import get_network_driver
import json

Now connect to the Cisco router using the below code. The first line includes the network driver. The second line includes device details such as IP address, username and password, and the third line uses the “” method to connect to a router.

driver = get_network_driver('ios')
device = driver('','developer','C1sco12345')

The below line of code uses the command get_facts() to retrieve device information. Here, I’m also using JSON to format the output for better viewing.


Finally, close the connection to the device.



  "uptime": 15180.0,
  "vendor": "Cisco",
  "os_version": "Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.1a, RELEASE SOFTWARE (fc3)",
  "serial_number": "9ESGOBARV9D",
  "model": "CSR1000V",
  "hostname": "csr1000v-1",
  "fqdn": "csr1000v-1.lab.devnetsandbox.local",
  "interface_list": [

In the above code, get_facts displays information such as uptime, vendor, serial number, hostname and also includes other details.

Complete Code

from napalm import get_network_driver
import json
driver = get_network_driver('ios')
device = driver('','developer','C1sco12345')

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s