第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何提取MAC ID?

如何提取MAC ID?

慕哥6287543 2021-12-21 16:17:04
我需要從一組相關(guān)命令中提取 MAC id。從第一個命令開始,括號內(nèi)的值 (2,4)eth-1(2-04)應用于第二個命令以從第二個命令的輸出中提取 MAC id。如何在第二個命令的輸出中提取與 2 4 位于同一行的 MAC id?s1 = '''100 int-maint      debug(2-02) eth-10(2-00) maint(4-03)101 bear-test      eth-1(2-04) eth-2(2-07)102 int-test      eth-4(2-06) eth-7(2-05) eth-8(2-03) eth-9(2-01) gig-3(2-08) eth-3(4-02) eth-5(4-00) eth-6(4-01) gig-1(4-08) gig-2(4-10) poe-1(4-04) poe-2(4-05) poe-3(4-06) poe-4(4-07)'''# output of second commandr2 = '''     2     4   101  00:80:a3:bf:72:d4      5     2    10   101  00:e0:4b:52:56:56      7     2    10   100  02:00:00:64:00:00      7     2    10   102  02:00:00:66:00:00      6     2     0   100  94:10:3e:b9:4f:5c      2Switch  Port   FID      MAC-Address    Aging     4     3   100  56:1a:5e:a2:4a:73      7'''import res1o = (next((x for x in s1.split() if 'eth-1(2-04)' in x), None))print(s1o)print(r2.split())到目前為止,我有輸出(如下所示)。我不確定 split() 是否是分解它以提取此值的最佳方法 00:80:a3:bf:72:d4eth-1(2-04)['2', '4', '101', '00:80:a3:bf:72:d4', '5', '2', '10', '101', '00:e0:4b:52:56:56', '7', '2', '10', '100', '02:00:00:64:00:00', '7', '2', '10', '102', '02:00:00:66:00:00', '6', '2', '0', '100', '94:10:3e:b9:4f:5c', '2', 'Switch', 'Port', 'FID', 'MAC-Address', 'Aging', '4', '3', '100', '56:1a:5e:a2:4a:73', '7']預期結(jié)果:00:80:a3:bf:72:d4
查看完整描述

2 回答

?
撒科打諢

TA貢獻1934條經(jīng)驗 獲得超2個贊

我也是python初學者,我覺得這段代碼對你有幫助


101 bear-test      eth-1(2-04) eth-2(2-07)

102 int-test      eth-4(2-06) eth-7(2-05) eth-8(2-03) eth-9(2-01) gig-3(2-08) eth-3(4-02) eth-5(4-00) eth-6(4-01) gig-1(4-08) gig-2(4-10) poe-1(4-04) poe-2(4-05) poe-3(4-06) poe-4(4-07)

'''

# output of second command


r2 = '''

     2     4   101  00:80:a3:bf:72:d4      5

     2    10   101  00:e0:4b:52:56:56      7

     2    10   100  02:00:00:64:00:00      7

     2    10   102  02:00:00:66:00:00      6

     2     0   100  94:10:3e:b9:4f:5c      2

Switch  Port   FID      MAC-Address    Aging

     4     3   100  56:1a:5e:a2:4a:73      7

'''



import re

s1o = (next((x for x in s1.split() if 'eth-1(2-04)' in x), None))

print(s1o)

base_list=(r2.split())

base_str=",".join(base_list)

pattren=r"(\w{2}):(\w{2}):(\w{2}):(\w{2}):(\w{2}):(\w{2})"

all_mac=re.findall(pattren,base_str)

print(all_mac)

print('###########################################')

for i in all_mac:

    result=re.sub(",",":",str(i))

    print(result)


查看完整回答
反對 回復 2021-12-21
?
慕的地6264312

TA貢獻1817條經(jīng)驗 獲得超6個贊

對于第一個命令,您可以應用此模式 eth-1\((\d)-0(\d)

eth-1\(=eth-1(字面上匹配

(\d) - 匹配數(shù)字并將其存儲在第一個捕獲組中

-0--0從字面上匹配,

(\d) - 匹配數(shù)字并將其存儲在第二個捕獲組中

演示

現(xiàn)在,您可以創(chuàng)建另一個正則表達式以應用于第二個命令: 2\s+4\s+\d+\s+([^\s]+)

2- 從字面上匹配 2,這來自第一個正則表達式的第一個捕獲組

\s+ - 匹配一個或多個空格

4- 從字面上匹配 4,這來自第一個正則表達式的第二個捕獲組

\s+ - 匹配一個或多個空格

\d+ - 匹配一位或多位數(shù)字

\s+ - 匹配一個或多個空格

([^\s]+)- 匹配一個或多個除空格之外的字符并將其存儲在捕獲組中,這將捕獲您的 mac 地址

演示


查看完整回答
反對 回復 2021-12-21
  • 2 回答
  • 0 關(guān)注
  • 202 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號