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

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

只走特定的節點

只走特定的節點

狐的傳說 2021-05-07 14:27:20
我正在構建一個腳本,該腳本應該通過SNMP(漫游)從調制解調器獲取MAC / IP地址。為此,我正在使用PySNMP和nextCmd(asyncore)。盡管我得到了想要的東西,但是目前我得到的比預期的要多:在特定節點上行走之后,它會與剩下的所有其他節點一起繼續工作。代碼:nextCmd(snmpEngine,        CommunityData('private'),        UdpTransportTarget(('IP.goes.right.here', 161)),        ContextData(),        ObjectType(ObjectIdentity('1.3.6.1.2.1.4.22.1.2')),        cbFun=cbFun)snmpEngine.transportDispatcher.runDispatcher()cbFundef cbFun(snmpEngine, sendRequestHandle, errorIndication,      errorStatus, errorIndex, varBindTable, cbCtx):if errorIndication:    print(errorIndication)    returnelif errorStatus:    print('%s at %s' % (errorStatus.prettyPrint(),                        errorIndex and varBindTable[-1][int(errorIndex) - 1][0] or '?'))    returnelse:    for varBindRow in varBindTable:        for varBind in varBindRow:            print(' = '.join([x.prettyPrint() for x in varBind]))return True 這純粹是基于文檔和Internet上的其他一些示例。樣本輸出:1.3.6.1.2.1.4.22.1.2.536870914.some.ip.was.here = 0xMacAddress1.3.6.1.2.1.4.22.1.3.1182728.some.ip.was.here = some.ip.was.here  # next node1.3.6.1.2.1.4.22.1.4.1182736.some.ip.was.here = 3  # and even further...因此,這樣做的意圖僅限于步行1.3.6.1.2.1.4.22.1.2。PS我只是從PySNMP開始,我想要類似 snmpwalk -v 2c -c private some.ip.was.here ipNetToPhysicalPhysAddress
查看完整描述

2 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

缺少解決此問題的任何內置方法,我對進行了更改cbFun()?,F在,它包含一些額外的行,re.search()并且pattern是OID(因此,如果pattern不匹配,即nextCmd轉到另一個級別(節點),它就可以了return)。我已經很簡單了,因為已經構造了帶有response的字符串print(' = '.join([x.prettyPrint() for x in varBind])),所以我已經添加了if條件,并將上面代碼的結果分配給了變量,因此使實現此檢查成為可能。

作為另一種可能的解決方案,也可以使用示例中描述的方法-使用varBindHead并進行比較。

隨時添加您的解決方案。


查看完整回答
反對 回復 2021-05-11
  • 2 回答
  • 0 關注
  • 293 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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