[SNMP4J] SNMPv3 problem
kenping liu
kenpingliu at yahoo.com.cn
Thu May 18 04:42:50 CEST 2006
Here is my codes:
Address targetAddress = GenericAddress.parse("udp:10.23.6.128/161");
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
MPv3 mpv3 = (MPv3) snmp
.getMessageProcessingModel(MessageProcessingModel.MPv3);
USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
mpv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
// create the target
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("myname"));
// create the PDU
PDU pdu = new ScopedPDU();
pdu.add(new VariableBinding(new OID("1.3.6")));
pdu.setType(PDU.GETNEXT);
// add the correct USM
snmp.getUSM().addUser(
new OctetString("myname"),
new UsmUser(new OctetString("myname"),
AuthMD5.ID, new OctetString("aaaaaaaa"),
PrivDES.ID, new OctetString("pppppppp")));
System.out.println(snmp.send(pdu, target).getResponse());
// add the wrong USM
snmp.getUSM().updateUser(new UsmUserEntry(new OctetString("myname"),
new UsmUser(new OctetString("myname"),
AuthMD5.ID, new OctetString("xxxxxxxxxxx"),
PrivDES.ID, new OctetString("pppppppp"))));
System.out.println(snmp.send(pdu, target).getResponse());
thanks.
Yours kenping
---------------------------------
雅虎免费邮箱-3.5G容量,20M附件
雅虎助手-搜索、杀毒、防骚扰
---------------------------------
抢注雅虎免费邮箱-3.5G容量,20M附件!
More information about the SNMP4J
mailing list