2017-01-17 81 views
-1

如何在java中獲取MIB-table的所有值?存在一個API來做到這一點?我正在構建一個管理器來獲取路由器計數器來估計性能。獲取值屬性MIB-表snmp

+0

歡迎堆棧溢出!請[編輯]你的問題,以顯示[你迄今爲止所嘗試的](http://whathaveyoutried.com)。您應該包含您遇到問題的代碼[mcve],然後我們可以嘗試幫助解決特定問題。你還應該閱讀[問]。 –

回答

0

您可以使用snmp4j-framework

代碼示例:

final Address targetAddress = GenericAddress.parse("X.X.X.X/80"); 
final TransportMapping transport = new DefaultUdpTransportMapping(); 
final Snmp snmp = new Snmp(transport); 
snmp.listen(); 
final CommunityTarget target = new CommunityTarget(); 
target.setCommunity(new OctetString("public")); 
target.setAddress(targetAddress); 
target.setRetries(80); 
target.setTimeout(1500); 
target.setVersion(SnmpConstants.version2c); 
final PDUFactory pduFactory = new DefaultPDUFactory(PDU.GETBULK); 
final TableUtils utils = new TableUtils(snmp, pduFactory); 
return utils.getTable(target, new OID[]{ query }, null, null);