[SNMP4J] Basic test run question
Tetsuro Motoyama
motoyama at str.ricoh.com
Thu Dec 3 01:37:25 CET 2009
I am new to the snmp4j and trying to test if I can run the simple program.
I took sample from SNMP class and created the following program that is
not working. It compiles and runs with the outputs below.
Can anyone help me?
===================================================================
package Test;
import java.io.IOException;
import org.snmp4j.*;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.event.ResponseListener;
import org.snmp4j.mp.MPv3;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.security.SecurityModels;
import org.snmp4j.security.SecurityProtocols;
import org.snmp4j.security.USM;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;
public class TestClass {
/**
* @param args
*/
@SuppressWarnings("deprecation")
public static void main(String[] args) {
Address targetAddress =
GenericAddress.parse("udp:172.30.4.51/161");
TransportMapping transport = null;
try {
transport = new DefaultUdpTransportMapping();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Snmp snmp = new Snmp(transport);
// setting up target
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(100000);
target.setVersion(SnmpConstants.version1);
// creating PDU
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new int[]
{1,3,6,1,2,1,1})));
pdu.setType(PDU.GETNEXT);
// sending request
ResponseEvent response = null;
try {
//response = snmp.send(pdu, target);
response = snmp.getNext(pdu, target);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Exception error = response.getError();
PDU responsePDU = response.getResponse();
// extract the address used by the agent to send the
response:
Address peerAddress = response.getPeerAddress();
System.out.println("done: " + response);
System.out.println("\nError is" + error);
System.out.println("\n"+responsePDU);
System.out.println("\n" + peerAddress);
}
}
====================================================
Outputs are:
---------------------
done: org.snmp4j.event.ResponseEvent[source=org.snmp4j.Snmp at 192b996]
Error isnull
null
null
More information about the SNMP4J
mailing list