[SNMP4J] SNMP Agent discovery

Shraddha Herlekar shraddha.herlekar at hds.com
Tue Jul 1 00:05:38 CEST 2014


Hi Frank,

Thank you for your reply. Following your suggestion I implemented the method shown below. It doesn't test broadcast yet. It is currently calling GET method on an agent.
After sending async request (using snmp.send(pdu, target, null, listener);), I think 'onResponse' method is never invoked.
I am not sure what am I missing. Could you please help?
Thanks!!

public static void testBroadcast() throws IOException {
		Address targetAddress = GenericAddress.parse("udp:172.17.77.112/161");
		// Broadcast address:
		// Address targetAddress = new UdpAddress("172.17.77.255/161");
		TransportMapping transport;

		try {
			transport = new DefaultUdpTransportMapping();
			transport.listen();
			snmp = new Snmp(transport);
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		// setting up target
		CommunityTarget target = new CommunityTarget();
		target.setCommunity(new OctetString("public"));
		target.setAddress(targetAddress);
		target.setRetries(2);
		target.setTimeout(5000);
		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,
				0 })));
		pdu.add(new VariableBinding(new OID(new int[] { 1, 3, 6, 1, 2, 1, 1, 2,
				0 })));
		pdu.setType(PDU.GET);
		System.out.println("Sending async request");

		// send Async request
		ResponseListener listener = new ResponseListener() {
			public void onResponse(ResponseEvent resEvent) {
				// 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) resEvent.getSource()).cancel(resEvent.getRequest(),
						this);
				System.out.println("Received response PDU is: "
						+ resEvent.getResponse());
			}
		};

		snmp.send(pdu, target, null, listener);

	}

Thanks,
Shraddha.

-----Original Message-----
From: SNMP4J [mailto:snmp4j-bounces at agentpp.org] On Behalf Of Frank Fock
Sent: Friday, June 27, 2014 11:53 AM
To: snmp4j at agentpp.org
Subject: Re: [SNMP4J] SNMP Agent discovery

Hi Shraddha,

Yes, of course. MIB Explorer is based on SNMP4J and its network discovery engine is based on SNMP4J.
Use the asynchronous request interface in conjunction with the broadcast address and use the cancel method by timeout (and not for each response as usual).

Best regards,
Frank

Am 27.06.2014 19:21, schrieb Shraddha Herlekar:
> Hi,
>
> Is it possible to discover SNMP agents in a network using SNMP4J?
> I am looking for a functionality that any MIB browser provides for Network Discovery, which results into list of SNMP agents, IP Address, sysDescr ..etc, given a Subnet IP.
>
> TIA,
> Shraddha.
>
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> https://oosnmp.net/mailman/listinfo/snmp4j

--
---
AGENT++
Maximilian-Kolbe-Str. 10
73257 Koengen, Germany
https://agentpp.com
Phone: +49 7024 8688230
Fax:   +49 7024 8688231

_______________________________________________
SNMP4J mailing list
SNMP4J at agentpp.org
https://oosnmp.net/mailman/listinfo/snmp4j


More information about the SNMP4J mailing list