[SNMP4J] Determine if an agent supports SNMPv2c

Rodolfo Josÿffffe9 Castellanos Jaimes rodolfojcj at yahoo.com
Mon Mar 14 15:25:36 CET 2005


Hi friends. I hope all of you be very well.

I have a doubt about how to determine in a reliable
way if an agent supports SNMPv2c.

That I know is that for version 1 the agent implements
the MIB-II specified by RFC 1213 and has the PDUs
GetRequest, GetNextRequest, SetRequest, GetResponse
and Trap. In the case of v2c the RJC 1907 defines the
enhancements of MIB-II and the PUDs are GetRequest,
GetNextRequest, GetBulkRequest, SetRequest,
InformRequest, Response and SNMPv2-Trap. (Stallings,
1999)

Well, using SNMP4J, I've done a Java class that
determines if a given host supports v1. The code is
something like this:

///////////// test v1 support

 Address targetAddress = 
   GenericAddress.parse( targetHost + "/" + snmpPort
);
 TransportMapping transport = 
   new DefaultUdpTransportMapping();
 Snmp snmp = new Snmp( transport );
 transport.listen();

 // setting up target
 CommunityTarget target = new CommunityTarget();
 target.setCommunity( new OctetString( "public" ) );
 target.setAddress( targetAddress );
 target.setRetries( 2 );
 target.setTimeout( 350 );
 target.setVersion( SnmpConstants.version1 );

 // creating request PDU
 PDU requestPDU = new PDU();
 // request "sysName" variable, because its status is
 // "mandatory" then any Snmp agent must respond to
 // this request
 requestPDU.add( new VariableBinding( 
 new OID( new int[] {1,3,6,1,2,1,1,5,0} ) ) );
 requestPDU.setType( PDU.GET );

 // sending request
 PDU responsePDU = null;
 ResponseEvent responseEvent = null;

 responseEvent = snmp.send( requestPDU, target );
 if ( responseEvent != null )
   responsePDU = responseEvent.getResponse();
 snmp.close();
			
 if ( responsePDU != null) // there was a response
   System.out.println( "The device supports SNMPv1" );
 else
   System.out.println( "Device doesn't support SNMPv1"
);

/////////////

Next, I modified the code to test if a device supports
SNMPv2c. I wrote "target.setVersion(
SnmpConstants.version2c )" and sent the same PDU
(requesting 1.3.6.1.2.1.1.5.0) and, for a device that
I know that only has support for version 1, I'm
getting a response; and it wasn't that I
was expecting because I specified version2c
(SnmpConstants.version2c). Here is probably that I
have a misunderstanding about the fields
SnmpConstants.version1 and SnmpConstants.version2c.
But, that I undernstand about it is that I can specify
which message processing model are we using when
communicating with the target host.

Then, I'm thinking about request an OID that is only
present in RFC 1907 (for example sysORLastChange
1.3.6.1.2.1.1.8.0) or specify a PDU GetBulk because
any of them is only specified for version 2 of SNMP.
If I get a positive response, then the device supports
this last version.
But actually I'm not sure if applying this approach
I'll get a reliable diagnose.

What do you think about this ?
Which could be a better point of view to determine
which version of SNMP is an agent running (that, in
last case, is that I want to do) ?

Any comment, suggestion, help, etc. will be welcome.

Thanks in advance by your time and attention.
Rodolfo José Castellanos Jaimes.

_________________________________________________________
Do You Yahoo!?
Información de Estados Unidos y América Latina, en Yahoo! Noticias.
Visítanos en http://noticias.espanol.yahoo.com



More information about the SNMP4J mailing list