* @(#)SnmpGetBulk.java * Copyright (c) 2012 ZOHO Corp. All Rights Reserved. * Please read the associated COPYRIGHTS file for more details. */ /** * This is an example program to explain how to write an * application to retrieve information about the * atTable entries in the localhost's RFC1213-MIB using * com.adventnet.snmp.snmp2 package of WebNMS SNMP API. * * The user could run this application by giving the following usage. * * java SnmpGetBulk * * import java.lang.*; import java.util.*; import java.net.*; import com.adventnet.snmp.snmp2.*; public class SnmpGetBulk { public static void main(String args[]) { // Start SNMP API SnmpAPI api = new SnmpAPI(); // Open session SnmpSession session = new SnmpSession(api); try { session.open(); } catch (SnmpException e ) { System.err.println("Error opening socket: "+e); } // Build GetBulk request PDU SnmpPDU pdu = new SnmpPDU(); UDPProtocolOptions option = new UDPProtocolOptions("localhost"); pdu.setProtocolOptions(option); pdu.setCommand(SnmpAPI.GETBULK_REQ_MSG ); pdu.setMaxRepetitions(10); pdu.setNonRepeaters(0); // Provide the OID .1.3.6.1.2.1.3.1 SnmpOID oid = new SnmpOID("1.3.1"); pdu.addNull(oid); // Send PDU and receive response PDU SnmpPDU result = session.syncSend(pdu); if (result == null) { System.out.println("Request timed out!"); } else { if (result.getErrstat()== 0) { // print the response pdu varbinds System.out.println(result.printVarBinds()); } else { System.out.println(result.getError()); } } // close session session.close(); // close api thread api.close(); } }