Tariq
Tariq

Reputation: 101

How to find "down" interfaces?

I'm trying to build a Python script where it first shows the description of interface, then checks if the interface has ( up up ) or (up down ) no action need else if the interface is ( down down) then print the interface name.

Here's the output before applying the script

Switch# show int description | section ABC
Hu1/0/14                       up             up       ABC
Hu1/0/30                       up             down     ABC
Hu1/0/31                       down           down     ABC

The output after apply the script should be

Hu1/0/31

Upvotes: -1

Views: 196

Answers (1)

Vishnu Indusekharan
Vishnu Indusekharan

Reputation: 41

There are multiple ways to talk to a network device like telnet, ssh, netconf etc and module available for each of those methods.

Sample code which should do what you need

import re
from netmiko import ConnectHandler

username = "test"
password = "test"
enablePwd = "test"

verification_cmd = 'show int description | section ABC'

net_connect = ConnectHandler(device_type="cisco_ios",ip=host,username=userName,password=passWord,secret=enablePwd)
net_connect.enable()
sh_command_output = net_connect.send_command(verification_cmd)


for line in sh_command_output.split('\n'):
    if re.findall(r'down.*down', line):
        print(line.split(' ')[0])

Upvotes: 1

Related Questions