[SNMP4J] Discover SNMPv3 Devices

Daniel Boschofsky d.boschofsky at gmail.com
Tue Feb 15 09:27:59 CET 2011


Hi there,

I am pretty new to mailinglists and SNMP4J.

I am trying to write a little application which lists all SNMPv3 devices in
the network and show some information. Reading information from a single
known host is no problem at all, but I cant discover all devices. I tried it
via a simple broadcast but it ends with a NullPointerException. If I use the
snmpgetnext command from bash, I get an "Unknown Engine ID (Permission
denied)". Probably it is the same problem with SNMP4J. So how can I send a
simple SNMPv3 request to all nodes without incrementing the IP and sending
the request to each existing address in the network.

Sincerely,
Daniel B.

---
My code so far for testing:

public static void main(String[] args) {
Snmp snmp;
Address targetAddress = GenericAddress.parse("udp:10.13.255.255/161");
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(),
new OctetString(MPv3.createLocalEngineID()),
0);

SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();

snmp.getUSM().addUser(new OctetString("HelloSnmp"),
new UsmUser(new OctetString("HelloSnmp"),
AuthMD5.ID,
new OctetString("Hello123"),
PrivDES.ID,
new OctetString("Hello123")));

UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(5000);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(new OctetString("HelloSnmp"));

OID targetOID = new OID(".1.3.6.1.2.1.1.5");
PDU pdu = new ScopedPDU();
pdu.add(new VariableBinding(targetOID));
pdu.setType(PDU.GETNEXT);

ResponseEvent response = snmp.send(pdu,target);
PDU responsePDU = response.getResponse();
System.out.println(responsePDU.get(0));
snmp.close();
}



More information about the SNMP4J mailing list