亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

通過 Cisco Config 解析

通過 Cisco Config 解析

滄海一幻覺 2021-06-04 17:43:33
我一直在嘗試編寫一個 Python 腳本來完成 20 種思科配置。到目前為止,我得到了一個腳本來處理一個配置,它解析出沒有802.1x authentication*接口命令的接口。我無法從列表中刪除interface Tengig和interface vlan*。最好的方法是什么?我嘗試了以下方法但沒有成功。也許我只是用錯了它們?list.remove(Interface Vlan*) for item in list(NoDot1x):  somelist.remove("Interface Vlan*")代碼:    #Int Modules    from ciscoconfparse import CiscoConfParse    #Define what to Parse    parse = CiscoConfParse("/home/jbowers/Configs/SwithConfig")    #Define all Interfaces without Authentication * commands    all_intfs = parse.find_objects(r"^interf")    NoDot1x = list()    NoDot1x = parse.find_objects_wo_child(r'^interface', r'authentication')   #Display Results   for obj in NoDot1x:       print obj.text   #Remove Uplinks   for item in list(NoDot1x):     somelist.remove("Interface Vlan*")這里是#Display Results 的輸出。interface Port-channel1interface FastEthernet1interface GigabitEthernet1/1interface TenGigabitEthernet5/1interface TenGigabitEthernet5/2interface TenGigabitEthernet5/3interface TenGigabitEthernet5/4interface TenGigabitEthernet5/5interface TenGigabitEthernet5/6interface TenGigabitEthernet5/7interface TenGigabitEthernet5/8interface TenGigabitEthernet6/1interface TenGigabitEthernet6/2interface TenGigabitEthernet6/3interface TenGigabitEthernet6/4interface TenGigabitEthernet6/5interface TenGigabitEthernet6/6interface TenGigabitEthernet6/7interface TenGigabitEthernet6/8interface GigabitEthernet7/23interface GigabitEthernet8/17interface GigabitEthernet9/2interface Vlan1
查看完整描述

1 回答

?
白衣染霜花

TA貢獻1796條經驗 獲得超10個贊

Python 中 list 對象提供的 remove 函數將嘗試找到與輸入的字符串完全匹配的內容,如果找到則刪除,否則會出錯。


#Remove Uplinks

for item in list(NoDot1x):

 somelist.remove("Interface Vlan*")

以上不會使用通配符“*”。我想你想要更像的東西:


for item in list(NoDot1x):

 if "Interface Vlan" in item:

  somelist.remove(item)

如果您需要更多復雜性,請查看重新導入。


查看完整回答
反對 回復 2021-06-06
  • 1 回答
  • 0 關注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號