I have some network output which i would like to return only certain prefixes based on conditions.
From the below output, I would like to return a list of all destinations which have the same destination, but different protocol. For example, for the destination 10.11.8.18/32, we have this via protocol 'O_ASE2' and 'BGP instance default', so the output should look something like this;
Destination: 10.11.8.18/32 Protocol: O_ASE2 Preference: 150 Protocol: BGP instance default Preference: 255
All the other entries should be ignored.
I've tried to work with regex and what not, but my regex skills are lacking.
If someone can assist, that would be great!
Thank you
Destination: 10.0.0.0/8 Protocol: O_ASE2 Process ID: 2 SubProtID: 0x8 Age: 27d03h34m48s Cost: 1 Preference: 150 IpPre: N/A QosLocalID: N/A Tag: 3489725548 State: Inactive Adv OrigTblID: 0x0 OrigVrf: default-vrf TableID: 0x102 OrigAs: 0 NibID: 0x13000016 LastAs: 0 AttrID: 0x12000003 Neighbor: 0.0.0.0 Flags: 0x41 OrigNextHop: 10.10.2.1 Label: NULL RealNextHop: 10.10.2.1 BkLabel: NULL BkNextHop: N/A Tunnel ID: Invalid Interface: Vsi-interface20000 BkTunnel ID: Invalid BkInterface: N/A FtnIndex: 0x0 TrafficIndex: N/A Connector: N/A PathID: 0x0
Destination: 10.11.0.0/16 Protocol: O_ASE1 Process ID: 2 SubProtID: 0x4 Age: 33d04h56m51s Cost: 3 Preference: 150 IpPre: N/A QosLocalID: N/A Tag: 0 State: Active Adv OrigTblID: 0x0 OrigVrf: default-vrf TableID: 0x102 OrigAs: 0 NibID: 0x13000012 LastAs: 0 AttrID: 0x12000002 Neighbor: 0.0.0.0 Flags: 0x10041 OrigNextHop: 10.10.2.1 Label: NULL RealNextHop: 10.10.2.1 BkLabel: NULL BkNextHop: N/A Tunnel ID: Invalid Interface: Vsi-interface20000 BkTunnel ID: Invalid BkInterface: N/A FtnIndex: 0x0 TrafficIndex: N/A Connector: N/A PathID: 0x0
Destination: 10.11.8.18/32 Protocol: O_ASE2 Process ID: 2 SubProtID: 0x8 Age: 12d02h38m51s Cost: 1 Preference: 150 IpPre: N/A QosLocalID: N/A Tag: State: Active Adv OrigTblID: 0x0 OrigVrf: default-vrf TableID: 0x102 OrigAs: 0 NibID: 0x13000016 LastAs: 0 AttrID: 0x12000003 Neighbor: 0.0.0.0 Flags: 0x10041 OrigNextHop: 10.10.2.1 Label: NULL RealNextHop: 10.10.2.1 BkLabel: NULL BkNextHop: N/A Tunnel ID: Invalid Interface: Vsi-interface20000 BkTunnel ID: Invalid BkInterface: N/A FtnIndex: 0x0 TrafficIndex: N/A Connector: N/A PathID: 0x0
Destination: 10.11.8.18/32 Protocol: BGP instance default Process ID: 0 SubProtID: 0x10 Age: 12d02h38m51s Cost: 0 Preference: 255 IpPre: N/A QosLocalID: N/A Tag: 0 State: Inactive Adv OrigTblID: 0x0 OrigVrf: default-vrf TableID: 0x102 OrigAs: 0 NibID: 0x18000000 LastAs: 0 AttrID: 0xffffffff Neighbor: 10.10.3.1 Flags: 0x4000040 OrigNextHop: 10.10.3.1 Label: NULL RealNextHop: 10.10.3.1 BkLabel: NULL BkNextHop: N/A Tunnel ID: Invalid Interface: Vsi-interface30000 BkTunnel ID: Invalid BkInterface: N/A FtnIndex: 0x0 TrafficIndex: N/A Connector: N/A PathID: 0x0
You can use this regex along with findall
:
"Destination: (?P<ip>(?:\d+\.?)+\/\d+)\s+Protocol: (?P<protocol>\w+)"
Matches:
[('10.0.0.0/8', 'O_ASE2'), ('10.11.0.0/16', 'O_ASE1'), ('10.11.8.18/32', 'O_ASE2'), ('10.11.8.18/32', 'BGP')]
Then you can group by the IP.
User contributions licensed under CC BY-SA 3.0