Been trying to regex the following but so far have failed.
Trying to catch a multicast bug in a router. The bug is a multicast where the outgoing interface is a Bundle-Ether(ether bundles only) and is not correlated to a physical linecard.
Example output is below:
(192.168.72.140,232.95.240.51) RPF nbr: 10.0.34.89 Flags: RPF
Up: 4w4d
Incoming Interface List
Bundle-Ether20 Flags: A, Up: 4w4d
Outgoing Interface List
Bundle-Ether5 (0/0/CPU0) Flags: F NS, Up: 4w4d
(192.168.137.7,232.95.240.68) RPF nbr: 10.0.34.242 Flags: RPF
Up: 20:50:13
Incoming Interface List
Bundle-Ether5 Flags: A, Up: 20:50:13
Outgoing Interface List
Bundle-Ether20 (0/2/CPU0) Flags: F NS, Up: 20:50:13
(192.168.137.12,232.95.240.71) RPF nbr: 10.0.34.242 Flags: RPF
Up: 4w4d
Incoming Interface List
Bundle-Ether5 Flags: A, Up: 23:09:53
Outgoing Interface List
Bundle-Ether12 (0/8/CPU0) Flags: F NS, Up: 4w4d
Bundle-Ether20 Flags: F NS, Up: 23:09:37
Bundle-Ether429 (0/7/CPU0) Flags: F NS, Up: 4w4d
You will notice that the last multicast (S,G = 192.168.137.12,232.95.240,71) has a Bundle-Ether, in the outgoing interface, where is goes directly from the interface to the "Flags". In this case "Bundle-Ether20 Flags:". While the interface of "Bundle-Ether429 (0/7/CPU0) Flags:" is not hitting the bug.
Trying to figure out how I only catch the multicasts that hit this bug and ignore the rest since my output can be thousands of line. Should I split the output into separate line and run a loop to process each line (and have nested loops for conditional matches)? Was hoping there was a Regex solution, preferably in python.
This works for the current input that you gave. It will work if the format remains the same throughout. If the format changes you can fine tune it. Let's make the input a bit more diverse and test our code:
(192.168.72.140,232.95.240.51) RPF nbr: 10.0.34.89 Flags: RPF
Up: 4w4d
Incoming Interface List
Bundle-Ether20 Flags: A, Up: 4w4d
Outgoing Interface List
Bundle-Ether5 (0/0/CPU0) Flags: F NS, Up: 4w4d
(192.168.137.7,232.95.240.68) RPF nbr: 10.0.34.242 Flags: RPF
Up: 20:50:13
Incoming Interface List
Bundle-Ether5 Flags: A, Up: 20:50:13
Outgoing Interface List
Bundle-Ether2011 Flags: F NS, Up: 23:09:37
(192.168.137.12,232.95.240.71) RPF nbr: 10.0.34.242 Flags: RPF
Up: 4w4d
Incoming Interface List
Bundle-Ether5 Flags: A, Up: 23:09:53
Outgoing Interface List
Bundle-Ether12 (0/8/CPU0) Flags: F NS, Up: 4w4d
Bundle-Ether20 Flags: F NS, Up: 23:09:37
Bundle-Ether429 (0/7/CPU0) Flags: F NS, Up: 4w4d
Bundle-Ether204 Flags: F NS, Up: 23:09:37
import re
with open(file.log, 'r') as f:
for entry in f.read().split('\n\n'):
req2=[]
req = entry.split()
req2.append(req[0])
i = req.index('Outgoing')+3
req2.append(req[i:])
res = re.findall(r'Bundle-Ether\d+\s*[^(]+?(?=Bundle-Ether|$)',' '.join(req2[1]))
if res:
req3= [req2[0]] + res
print req3
['(192.168.137.7,232.95.240.68)', 'Bundle-Ether2011 Flags: F NS, Up: 23:09:37']
['(192.168.137.12,232.95.240.71)', 'Bundle-Ether20 Flags: F NS, Up: 23:09:37 ', 'Bundle-Ether204 Flags: F NS, Up: 23:09:37']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.