#!/bin/env python import argparse import sys import cisco IP = 'IP-Address' MAC = 'Mac-Address' Vlan = 'Vlan' If = 'Interface' Desc = 'Description' IP_info = {IP:'None', MAC:'None', Vlan:'None', If:'None', Desc:'None'} def get_ARP_Table(ipaddr): arpCmd = 'sh ip arp ' + ipaddr arpCmdResult = CLI(arpCmd, False) # CLI 명령 시, 매개변수2에 False를 지정하지 않으면 화면에 해당 명령 결과값이 함께 출력된다. # Default 값은 True. arpCmdResultList = arpCmdResult.get_output() # CLI의 결과값을 cisco.cli.CLI type에서 각 Line별 값으로 List Type으로 변경 for arp in arpCmdResultList: if (-1 6): # Mac Address Table이 존재하지 않을 경우에는 1리턴, 존재시 7이상 리턴.(결과값라인) IP_info[Int] = macCmdResultList[5][58:] # Interface 정보만 가져옴. get_Description_info(IP_info[Int]) # Interface정보가 있는 경우에는 해당 Interface의 Desc를 가져옴. def get_Description_info(iInfo): if(iInfo.find('Eth') == 0 or iInfo.find('Po')==0): # Eht나 Po인 경우에만 Desc확인 intCmd = 'sh int desc | inc ' + iInfo intCmdResult = CLI(intCmd, False) intCmdResultList = intCmdResult.get_output() IP_info[Desc] = intCmdResultList[0][25:] def show_IP_info(): print '================================================' print ' IP Info : NetworkZIGI ' print '================================================' print '%-15s : %s' % (IP,IP_info[IP]) print '%-15s : %s' % (MAC,IP_info[MAC]) print '%-15s : %s' % (Vlan, IP_info[Vlan]) print '%-15s : %s' % (Int, IP_info[Int]) print '%-15s : %s' % (Desc,IP_info[Desc]) parser = argparse.ArgumentParser('Args',description='Args Desc') parser.add_argument('ip') args = parser.parse_args() iparp = get_ARP_Table(args.ip) get_IP_MAC_info(iparp) get_Interface_info() show_IP_info()