
achilder
New User
Feb 7, 2011, 10:39 AM
Post #1 of 4
(40794 views)
|
need a program that can parse show cdp neig into cvs format
|
Can't Post
|
|
Can someone help me with a perl script to do the following task: I have output from cdp neigh det from a buch of cisco routers that looks like this: router1#sh cdp neigh det ------------------------- Device ID: myrouter Entry address(es): IP address: 10.1.1.1 Platform: WS-C6509, Capabilities: Trans-Bridge Switch Interface: GigabitEthernet0/19, Port ID (outgoing port): 4/8 Holdtime : 123 sec Version : WS-C6509 Software, Version McpSW: 7.1(2) NmpSW: 7.1(2) Copyright (c) 1995-2002 by Cisco Systems advertisement version: 2 VTP Management Domain: 'EXP' Native VLAN: 6 Duplex: full Management address(es): IP address: 10.1.1.1 router1# router2#sh cdp neigh det ------------------------- Device ID: myrouter Entry address(es): IP address: 10.1.1.1 Platform: WS-C6509, Capabilities: Trans-Bridge Switch Interface: GigabitEthernet1/0/19, Port ID (outgoing port): 4/8 Holdtime : 129 sec Version : WS-C6509 Software, Version McpSW: 7.1(2) NmpSW: 7.1(2) Copyright (c) 1995-2002 by Cisco Systems advertisement version: 2 VTP Management Domain: 'EXP' Native VLAN: 201 Duplex: full Management address(es): IP address: 10.1.1.1 ------------------------- Device ID: myrouter Entry address(es): IP address: 10.1.1.1 Platform: WS-C6509, Capabilities: Trans-Bridge Switch Interface: GigabitEthernet1/0/19, Port ID (outgoing port): 9/1 Holdtime : 128 sec Version : WS-C6509 Software, Version McpSW: 7.1(2) NmpSW: 7.1(2) Copyright (c) 1995-2002 by Cisco Systems advertisement version: 2 VTP Management Domain: 'EXP' Native VLAN: 201 Duplex: full Management address(es): IP address: 10.1.1.1 router2# router3#sh cdp neigh det ------------------------- Device ID: johnsrouter Entry address(es): IP address: 10.2.2.2 Platform: cisco WS-C6506, Capabilities: Router Switch Interface: GigabitEthernet1/0/20, Port ID (outgoing port): GigabitEthernet2/2 Holdtime : 121 sec Version : Cisco Internetwork Operating System Software IOS (tm) c6sup2_rp Software (c6sup2_rp-PK9SV-M), Version 12.2(17d)SXB11a, RELEASE SOFTWARE (fc1) Technical Support: http://www.cisco.com/techsupport Copyright (c) 1986-2006 by cisco Systems, Inc. advertisement version: 2 VTP Management Domain: '' Native VLAN: 201 Duplex: full Management address(es): ------------------------- Device ID: bobsrouter Entry address(es): IP address: 10.3.3.3 Platform: WS-C6509, Capabilities: Trans-Bridge Switch Interface: GigabitEthernet1/0/10, Port ID (outgoing port): 8/4 Holdtime : 130 sec Version : WS-C6509 Software, Version McpSW: 7.1(2) NmpSW: 7.1(2) Copyright (c) 1995-2002 by Cisco Systems advertisement version: 2 VTP Management Domain: 'EXP' Native VLAN: 201 Duplex: full Management address(es): IP address: 10.3.3.3 router3# This is a short sample but my file will end up with 1000's of entries like this. What I am trying to do is this: Parse the file line by line. Look for Device ID: Copy text in Device ID after the : to the newline into a new file appended with a comma continue down the file looking for address: and copy the value after the : and before the newline into the file wher the device id went on the same line with the associated device with an appened comma. continue down the file and search for Platform: and copy the value between the : and newline to the file from above after the IP address Basically I am trying to end up with a comma delimted file. If the above data was run through my theoretical script it would lookslike this: myrouter, 10.1.1.1, WS-C6509, Capabilities: Trans-Bridge Switch myrouter, 10.1.1.1, WS-C6509, Capabilities: Trans-Bridge Switch myrouter, 10.1.1.1, WS-C6509, Capabilities: Trans-Bridge Switch johnsrouter, 10.2.2.2, cisco WS-C6506, Capabilities: Router Switch bobsrouter, 10.3.3.3, WS-C6509, Capabilities: Trans-Bridge Switch Caveats: once a device ID is found in the line by line only and ip address and platform within 15 lines should be used for creating that record. The reason for this is I may end up getting back cdp information that is non consistent. if this caveat is not in place it could throw off all record below the incomplete one. sometimes there will be multiple IP address on seperate lines. These should all be placed in the same record. The output for IP address is inconsistent. sometimes it is IP address: and sometimes address: Need to accomadate both capital letters in the the search need to be irrelevant here is an example of what a record with multiple ips would look like: Port (Our Port): 2/5 Device-ID: testbed Device Addresses: IP Address: 172.16.0.3 IP Address: 172.16.0.3 Holdtime: 126 sec Capabilities: TRANSPARENT_BRIDGE SWITCH Version: Cisco Internetwork Operating System Software IOS (tm) C3500XL Software (C3500XL-C3H2S-M), Version 12.0(5)WC10, RELEASE SOFTWARE (fc1) Copyright (c) 1986-2004 by cisco Systems, Inc. Platform: cisco WS-C3548-XL Port-ID (Port on Neighbors's Device): GigabitEthernet0/8 VTP Management Domain: EXP Native VLAN: unknown Duplex: full This would be an example of an alternate format I need to account for: wonky# sh cdp neigh det CDP neigbors information Port : 25 Device ID : wonky1 Address Type : IP Address : 192.168.1.1 Platform : HP 8000M Capability : S Device Port : D2 Version : Revision C.09.28 /sw/code/build/vgro(c09) wonky# I would creatley appreciate any help that anyone can provide with scripting his up.
|