snmp 模拟 errorStatus=Bad value(3)

1.  修改设备名称,节点为:1.3.6.1.2.1.1.5.0,代码如下:

public class SnmpTest {
    public static void main(String[] args) throws IOException {
        
        try {
            Snmp snmp = new Snmp(new DefaultUdpTransportMapping());
            snmp.listen();
            
            CommunityTarget target = new CommunityTarget();
            target.setAddress(GenericAddress.parse("udp:192.168.100.61/161"));
            target.setCommunity(new OctetString("private"));
            target.setRetries(2);
            target.setTimeout(100);
            target.setVersion(SnmpConstants.version1);
            target.setMaxSizeRequestPDU(Integer.MAX_VALUE);
            
            PDU pdu = new PDU();
            pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"),new OctetString("111111"
                    + "1111111111111111111111111111111111111111111111111111111111111111111111"
                    + "1111111111111111111111111111111111111111111111111111111111111111111111"
                    + "1111111111111111111111111111111111111111111111111111111111111111111111"
                    + "1111111111111111111111111111111111111111111111111111111111111111111111"
                    + "11111")));
            
            pdu.setType(PDU.SET);
            ResponseEvent event = snmp.send(pdu, target);
            PDU resp = event.getResponse();
            System.out.println(resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

2.结果为:

 3.

PDU长度的取值范围是: 484 - Integer.MAX_VALUE

原文地址:https://www.cnblogs.com/beibidewomen/p/7230099.html