java关闭snmp_java-如何防止SNMP4J GETBULK在OID之前不增加最...

我正在使用此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,它们是ifInMulticastPkt,然后有时是1.3.6.1.2.1.31.11.1.1.1.3,它们是ifInBroadcastPkt.我只对ifName感兴趣.

在遍历MIB之前如何防止GETBULK递增最后一位数字?

public ArrayList 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 responsePieces = new ArrayList();

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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值