如何使用 snmp4j 和社区字符串索引进行 snmpwalk?
我可以通过更改 public@123 之类的社区字符串来进行社区字符串索引(123 是 vlanId)
但这仅适用于 snmpget !!??:
public ResponseEvent get(OID oids) throws IOException {
PDU pdu = new PDU();
pdu.add(new VariableBinding(oid));
pdu.setType(PDU.GETNEXT);
ResponseEvent event = snmp.send(pdu, getTarget(), null);
}
private Target getTarget() {
Address targetAddress = GenericAddress.parse(sw.getAddress());
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(communityString));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version2c);
return target;
}
但是当我尝试像这样进行 snmpwalk 时,我会超时
public HashMap<String, String> snmpWalk(String strOid) throws IOException {
OID oid = new OID(strOid);
TreeUtils treeUtils = new TreeUtils(snmp, new DefaultPDUFactory());
HashMap<String, String> snmpResult = new HashMap<String, String>();
List<TreeEvent> events = treeUtils.getSubtree(getTarget(), oid);
// some more code ...
}