-1

I have a Cisco router and I need to know which interface is used for LAN. This is the show interface description output:

R1#sho int desc
Interface                      Status         Protocol Description
Em0/0                          admin down     down
Gi0/0                          up             up       LAN
Gi0/1                          up             up       WAN
Gi0/2                          up             up       Crosslink
Gi0/2.100                      up             up       Crosslink

I managed to login with pexpect and get the above output into a variable, but I'm not sure how to filter it:

execute.send('term len 0\n')
execute.expect(device['name'] + '#')

execute.send('sho int desc\n')
execute.expect(device['name'] + '#')
output = execute.before

I would like to have "Gi0/0" as a result.

Could you give me some ideas? Thanks!

human374
  • 113
  • 4

1 Answers1

0

I used the following code:

    execute.send('sho int desc\n')
    execute.expect(device['name'] + '#')
    output = execute.before

    for line in output.splitlines():
        if re.match('.*LAN.*', line):
            interfaceName = re.findall(r'[^\s]+' ,line)[0]

There must be a better solution. If you have any ideas please share them.

human374
  • 113
  • 4