Snmpv3Get.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: Snmpv3Get.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
- /*
- * @(#)Snmpv3Get.java
- * Copyright (c) 1999 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- /**
- * This is a tutorial example program to explain how to write an application to do
- * the basic SNMP operation GET using com.adventnet.snmp.beans package of
- * AdventNetSNMP api.
- *
- * The user could run this application by giving the following usage.
- *
- * java Snmpv3Get hostname OID
- *
- * where
- *
- * hostname is the RemoteHost (agent).The Format is string without double qoutes/IpAddress.
- * OID is the Object Identifier. The entire OID can be given or it can be given in the form of 1.1.0.
- * If the oid is not starting with a dot (.) it will be prefixed by .1.3.6.1.2.1 .
- * So the entire OID of 1.1.0 will become .1.3.6.1.2.1.1.1.0 .
- *
- * Example usage:
- *
- * java Snmpv3Get adventnet 1.1.0
- *
- */
- import com.adventnet.snmp.beans.*;
- public class Snmpv3Get {
- public static void main(String args[]) {
- if( args.length < 2)
-
- {
- System.out.println("Usage : java Snmpv3Get hostname OID ");
- System.exit(0);
- }
- // Take care of getting the hostname and the OID
- String remoteHost = args[0];
- String OID = args[1];
- // Instantiate the SnmpTarget bean
- SnmpTarget target = new SnmpTarget();
- //set host and other parameters
- target.setTargetHost(remoteHost);
- target.setObjectID(OID);
- target.setTargetPort(8001);
- target.setDebug(true);
- target.setSnmpVersion(3);
-
- target.setPrincipal("msiva"); // Set the user who made this request
- target.setAuthPassword("test"); // Set password for authentication
- target.setAuthProtocol(target.MD5_AUTH); // one SHA or MD5
- target.create_v3_tables(); // create SnmpEngineEntry and USMUserEntry
-
- // do the SNMP GET operation
- String result = target.snmpGet();
-
-
- // print the results
- System.out.println("OBJECT ID: "+target.getObjectID());
- System.out.println("Response: "+result);
- System.exit(0);
- }
- }