获取值属性MIB-Table snmp

时间:2017-01-17 15:10:32

标签: java snmp mib

如何在java中获取MIB表的所有值?存在api这样做?我正在构建一个管理器来获取路由器计数器来估计性能。

1 个答案:

答案 0 :(得分: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);