0% found this document useful (0 votes)
15 views1 page

Netmiko Config

The document contains a Python script that configures OSPF on a Cisco router using the Netmiko library. It connects to the router, sends OSPF configuration commands, retrieves the running configuration, and counts occurrences of 'Gigabit' in the output. The script is designed to be executed with specific router details provided in a dictionary.

Uploaded by

neomishra007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Netmiko Config

The document contains a Python script that configures OSPF on a Cisco router using the Netmiko library. It connects to the router, sends OSPF configuration commands, retrieves the running configuration, and counts occurrences of 'Gigabit' in the output. The script is designed to be executed with specific router details provided in a dictionary.

Uploaded by

neomishra007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import netmiko

def configure_ospf(router, process_id, area_id, network_list):

commands = [
f"router ospf {process_id}",
*[f"network {network} area {area_id}" for network in network_list]
]

with netmiko.ConnectHandler(**router) as ssh_conn: // ** is python syntax to


pass arguments to a function using dictionary
ssh_conn.enable()
ssh_conn.send_config_set(commands)
output = ssh_conn.send_command("Show run")

with open("output.txt", "w") as file: OR with open("output.txt" , "a")


file.write(output)

with open("output.txt", "r") as file


text = file.read()
count = text.count(Gigabit)

print(count)

if __name__ == "__main__":

router_details = {
"device_type": "cisco_ios",
"host": "192.168.1.1",
"username": "admin",
"password": "password",
"secret": "password" # If required
}

configure_ospf(router_details, 1, 0, ["10.0.0.0/8", "172.16.0.0/12"])

You might also like