我正在使用此SNMP4J代碼來執行一些SNMP操作。但是,當我運行它,如1.3.6.1.2.1.31.1.1.1.1這是ifName,它獲得所有接口,由1.3.6.1.2.1.31.1.1.1.1.x表示,但它然後它也抓取1.3.6.1.2.1.31.1.1.1.2,它們是ifInMulticastPkts,然後有時是1.3.6.1.2.1.31.1.1.1.3,它們是ifInBroadcastPkts。我只對ifName感興趣。如何讓SNMP4J GETBULK在OID之前遞增最右邊的數字?
如何防止GETBULK在遍歷MIB之前增加最後一位數字?
public ArrayList<String> walk(String oid) throws IOException, InterruptedException {
Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
snmp.listen();
Address targetAddress = GenericAddress.parse(address);
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(community));
target.setVersion(SnmpConstants.version2c);
target.setAddress(targetAddress);
target.setTimeout(3000); //3s
target.setRetries(1);
PDU pdu = new PDU();
pdu.setType(PDU.GETBULK);
pdu.setMaxRepetitions(200);
pdu.setNonRepeaters(0);
pdu.add(new VariableBinding(new OID(oid)));
ResponseEvent responseEvent = snmp.send(pdu, target);
PDU response = responseEvent.getResponse();
ArrayList<String> responsePieces = new ArrayList<String>();
if (response == null) {
System.out.println("TimeOut...");
}
else
{
if (response.getErrorStatus() == PDU.noError)
{
Vector<? extends VariableBinding> vbs = response.getVariableBindings();
for (VariableBinding vb : vbs) {
responsePieces.add(vb.toString());
}
}
else
{
System.out.println("Error:" + response.getErrorStatusText());
}
}
return responsePieces;
}