[SNMP4J] simple snmp get

Frank Fock fock at agentpp.com
Wed Sep 21 00:25:08 CEST 2005


Hi Afnan,

When using the Snmp() constructor you need to manually add the
MessageProcessingModels (MPV1,MPV2c, or MPv3) and
SecurityModels (USM) you want to use.

The current JavaDoc is wrong and will be fixed for the next release.

Best regards,
Frank

Afnan Chowdhury wrote:

>Hi All,
>
>I would be very glad if anyone response me with the solution of this
>problem. I am using SNMP4J library for the first time and need for a
>quick tick off using its all sorts of aspects of it but got stuck at
>the beginning. I am using Jbuilder with JDK 1.5 on a winxp mechine
>sending snmp get to a broadcase address.
>
>Many Thanks in advance.
>
>Afnan 
>
>
>
>Error message is 
>
>Exception in thread "main" org.snmp4j.MessageException: Unsupported
>message processing model: 0
>
>	at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:399)
>
>	at org.snmp4j.Snmp.sendMessage(Snmp.java:900)
>
>	at org.snmp4j.Snmp.send(Snmp.java:783)
>
>	at org.snmp4j.Snmp.send(Snmp.java:771)
>
>	at NetworkAlarmReportingTool.SNMPTest.main(SNMPTest.java:76)
>
>Source Code:
>
>
>import org.snmp4j.*;
>import java.lang.*;
>import org.snmp4j.smi.*;
>import org.snmp4j.transport.DefaultUdpTransportMapping;
>import org.snmp4j.event.ResponseEvent;
>import org.snmp4j.PDU;
>import org.snmp4j.smi.OctetString;
>import java.io.*;
>import org.snmp4j.smi.GenericAddress;
>import org.snmp4j.mp.SnmpConstants;
>import org.snmp4j.event.ResponseListener;
>
>
>public class SNMPTest {
>    public static void main(String[] args) throws IOException {
>
>
>        CommunityTarget target = new CommunityTarget();
>        Address targetAddress = GenericAddress.parse("udp:9.15.255.255/161");
>        //boolean a = targetAddress.isValid();
>        //System.out.print(a);
>
>        target.setCommunity(new OctetString("public"));
>        target.setAddress(targetAddress);
>        target.setRetries(2);
>        target.setTimeout(15000);
>        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,1})));
>        pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,2})));
>        pdu.setType(PDU.GETNEXT);
>   
>        // sending request
>        ResponseListener listener = new ResponseListener() {
>            public void onResponse(ResponseEvent event) {
>                // Always cancel async request when response has been received
>                // otherwise a memory leak is created! Not canceling a request
>                // immediately can be useful when sending a request to
>a broadcast
>                // address.
>                ((Snmp) event.getSource()).cancel(event.getRequest(), this);
>                System.out.println("Received response PDU is: " +
>                                   event.getResponse());
>            }
>        };
>
>        TransportMapping transport = null;
>                try {
>                    transport = new DefaultUdpTransportMapping();
>                } catch (IOException ex) {
>                }
>        Snmp s = new Snmp();
>        s.send(pdu,target,null,listener);
>    }
>}
>_______________________________________________
>SNMP4J mailing list
>SNMP4J at agentpp.org
>http://lists.agentpp.org/mailman/listinfo/snmp4j
>
>
>  
>


-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com





More information about the SNMP4J mailing list