1

Trying out Frank's simple snmpv3 example up on snmp4j.org and the following code keeps returning a REPORT with an OID of 1.3.6.1.6.3.15.1.1.3.0 which means UnknownUserName..

First, here is the sample snmpwalk that correctly connects and returns a table of OIDS..

snmpwalk -v3 -n DefaultContextName -l noAuthNoPriv -u "public-1" x.x.x.x:161 1.3.6.1.4.1.x

And the below snmp4j code

    public static void main(String[] args){

        try {

            System.out.println("DEBUG:MW>Initiated main...");

            Address targetAddress = GenericAddress.parse("udp:x.x.x.x/161");
            TransportMapping transport = new DefaultUdpTransportMapping();
            Snmp snmp = new Snmp(transport);
            USM usm = new USM(SecurityProtocols.getInstance(),
                    new OctetString(MPv3.createLocalEngineID()), 0);
            SecurityModels.getInstance().addSecurityModel(usm);
            transport.listen();

            // add user to the USM
//            snmp.getUSM().addUser(new OctetString("public-1"),
//                    new UsmUser(new OctetString("DefaultContextName"),
//                            null,
//                            null,
//                            null,
//                            null));
             snmp.getUSM().addUser(new OctetString("MD5DES"),
             new UsmUser(new OctetString("MD5DES"),
                         AuthMD5.ID,
                         new OctetString("readuser"),//MD5DESUserAuthPassword
                         PrivDES.ID,
                         new OctetString("readuser2")));//MD5DESUserPrivPassword

            // create the target
            UserTarget target = new UserTarget();
            target.setAddress(targetAddress);
            target.setRetries(1);
            target.setTimeout(10000);
            target.setVersion(SnmpConstants.version3);
            target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);
            target.setSecurityName(new OctetString("MD5DES"));

            // create the PDU
            PDU pdu = new ScopedPDU();
            pdu.add(new VariableBinding(new OID("1.3.6.1.4.1.x")));
            pdu.setType(PDU.GETNEXT);

            // send the PDU
            ResponseEvent response = snmp.send(pdu, target);
            // extract the response PDU (could be null if timed out)
            PDU responsePDU = response.getResponse();
            // extract the address used by the agent to send the response:
            Address peerAddress = response.getPeerAddress();

            System.out.println("DEBUG:MW: REVISED PDU toString>"+responsePDU.toString());


        }catch(Exception e){
            System.err.println(e.getMessage());
            e.printStackTrace();
        }

Above you may notice a commented-out USM object that properly has the 'public-1' username.. That always results in a timeout and therefore responsePDU is null.

Much Thanks ahead of time.. Like everyone else - I'm in a time crunch and really need some help!

user3341047
  • 33
  • 1
  • 6
  • Hi @user3341047 can you share me the working sample of snmpv3 if you were able to develop one - using snmp4j – chetan Sep 28 '17 at 12:58

0 Answers0