Re: [python.tw] 請問 Python 如何同時抓取 SNMP 的 "OID" 與 "值"

187 views
Skip to first unread message

evenrain

unread,
May 6, 2013, 5:13:51 AM5/6/13
to pyth...@googlegroups.com
我之前是用 pysnmp
sample 可以看 http://pysnmp.sourceforge.net/examples/current/index.html
我記得就可以取得 OID & Value



P.W. Chi <pwch...@gmail.com> 於 2013年5月6日下午4:15 寫道:
各位前輩好,

想請問是否有人用 Python 抓過 SNMP 的 OID 跟值過。

我透過 snmpwalk 撈出下面的 OID 跟值

iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.1 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.72 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.74 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.135 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.172 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.200 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.360 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.678 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.679 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.1002 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.1003 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.1004 = INTEGER: 1
iso.3.6.1.4.1.9.9.46.1.3.1.1.2.1.1005 = INTEGER: 1

因為希望用 Python 的 netsnmp module 也能撈出 oid 與值來做後續處理,所以寫了下面程式。

import netsnmp
oid = netsnmp.Varbind('.1.3.6.1.4.1.9.9.46.1.3.1.1.2')
result = netsnmp.snmpwalk(oid,Version = 2, DestHost="x.x.x.x",Community="xxxx")
print result

但是發現 Python 都只會回傳「值」,請問要如何讓 OID 也能一起傳回來呢?

('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1')

感謝大家

--
您已訂閱「Google 網上論壇」的「python.tw」群組,因此我們特別傳送這封郵件通知您。
如要取消訂閱這個群組並停止接收來自這個群組的郵件,請傳送電子郵件到 pythontw+u...@googlegroups.com
如要在此群組張貼留言,請傳送電子郵件至 pyth...@googlegroups.com
請前往以下網址造訪這個群組:http://groups.google.com/group/pythontw?hl=zh-TW。
如需更多選項,請前往:https://groups.google.com/groups/opt_out。
 
 

Reply all
Reply to author
Forward
0 new messages