#!/usr/bin/env python

'''
III. You have the following 'show ip int brief' output.

show_ip_int_brief = \'\'\'
Interface            IP-Address      OK?     Method      Status     Protocol
FastEthernet0   unassigned      YES     unset          up          up
FastEthernet1   unassigned      YES     unset          up          up
FastEthernet2   unassigned      YES     unset          down      down
FastEthernet3   unassigned      YES     unset          up          up
FastEthernet4    6.9.4.10          YES     NVRAM       up          up
NVI0                  6.9.4.10          YES     unset           up          up
Tunnel1            16.25.253.2     YES     NVRAM       up          down
Tunnel2            16.25.253.6     YES     NVRAM       up          down
Vlan1                unassigned      YES    NVRAM       down      down
Vlan10              10.220.88.1     YES     NVRAM       up          up
Vlan20              192.168.0.1     YES     NVRAM       down      down
Vlan100            10.220.84.1     YES     NVRAM       up          up
\'\'\'

From this output, create a list where each element in the list is a tuple consisting of (interface_name, ip_address, status, protocol).  Only include interfaces that are in the up/up state.

Print this list to standard output.
'''

from pprint import pprint

show_ip_int_brief = '''
Interface            IP-Address      OK?     Method      Status     Protocol
FastEthernet0   unassigned      YES     unset          up          up
FastEthernet1   unassigned      YES     unset          up          up
FastEthernet2   unassigned      YES     unset          down      down
FastEthernet3   unassigned      YES     unset          up          up
FastEthernet4    6.9.4.10          YES     NVRAM       up          up
NVI0                  6.9.4.10          YES     unset           up          up
Tunnel1            16.25.253.2     YES     NVRAM       up          down
Tunnel2            16.25.253.6     YES     NVRAM       up          down
Vlan1                unassigned      YES    NVRAM       down      down
Vlan10              10.220.88.1     YES     NVRAM       up          up
Vlan20              192.168.0.1     YES     NVRAM       down      down
Vlan100            10.220.84.1     YES     NVRAM       up          up
'''
formatter = "%-18s%-15s%-8s%-8s"

sh_ip_int_br = show_ip_int_brief.split('\n')[2:-1]
sh_ip_addr = []

print "=" * 60
print formatter % ("Interface Name", "IP-Address", "Status", "Protocol")

for line in sh_ip_int_br:
  if line.find("down") == -1:
    line = line.split()
    if_name = line[0]
    ip_addr = line[1]
    status = line[4]
    protocol = line[5]
    sh_ip_addr.append( (if_name, ip_addr, status, protocol) )
    print formatter % (if_name, ip_addr, status, protocol)

print "=" * 60
print ""
pprint(sh_ip_addr)
print ""
print "=" * 60
# The END

Create ex3_3.py