簡體   English   中英

查找多播傳出接口

[英]Find multicast outgoing interface

一直試圖正則表達以下但迄今為止都失敗了。

試圖捕獲路由器中的多播錯誤。 該錯誤是一種多播,其中出接口是Bundle-Ether(僅限以太束),並且與物理線卡無關。

示例輸出如下:

(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

您會注意到,最后一個多播(S,G = 192.168.137.12,232.95.240,71)在出接口中有一個Bundle-Ether,它直接從接口進入“Flags”。 在這種情況下“Bundle-Ether20 Flags:”。 雖然“Bundle-Ether429(0/7 / CPU0)Flags:”的界面沒有碰到這個bug。

試圖找出我如何只捕獲擊中此bug的多播並忽略其余部分,因為我的輸出可能是數千行。 我應該將輸出拆分為單獨的行並運行循環來處理每一行(並且有條件匹配的嵌套循環)? 希望有一個正則表達式解決方案,最好是在python中。

這適用於您提供的當前輸入。 如果整個格式保持不變,它將起作用。 如果格式發生變化,您可以對其進行微調。 讓我們使輸入更加多樣化並測試我們的代碼:

輸入文件:file.log

(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']

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM