SnmpSet.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: SnmpSet.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
- /*
- * @(#)SnmpSet.java
- * Copyright (c) 1996-2003 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 SET using com.adventnet.snmp.beans package of
- * AdventNetSNMP api.
- *
- * The user could run this application by giving the following usage.
- *
- * java SnmpSet hostname OID mibs value
- *
- * where
- *
- * hostname is the RemoteHost (agent).The Format is string without double qoutes/IpAddress.
- * OID is the Object Identifier. Multiple OIDs can also be given.
- * 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 .
- * mibs is the name of the MIB file that is loaded
- * value is the object instance value to be set
- *
- * Example usage:
- *
- * java SnmpSet adventnet 1.6.0 ../mibs/RFC1213-MIB testing...
- *
- */
- import com.adventnet.snmp.beans.*;
- public class SnmpSet {
- public static void main(String args[]) {
- if( args.length < 4)
-
- {
- System.out.println("Usage : java SnmpSet hostname OID mibs value ");
- System.exit(0);
- }
-
- // Take care of getting the hostname, OID, mib file name and the value
- String remoteHost = args[0];
- String OID = args[1];
- String mibs = args[2];
- String value = args[3];
-
- // Instantiate the SnmpTarget bean
- SnmpTarget target = new SnmpTarget();
-
- //set host and other parameters
- target.setTargetHost(remoteHost);
- target.setObjectID(OID);
-
- // load the mib file
- try{
- target.loadMibs(mibs);
- } catch (Exception ex) {
- System.err.println("Error loading MIBs: "+ex);
- }
-
- //do the SNMP SET operation and print the results
- try {
- String result = target.snmpSet(value);
- System.out.println("Response PDU received from " +target.getTargetHost()+ ", community: " + target.getCommunity());
- System.out.println("OBJECT ID: "+target.getObjectID());
- System.out.println("Response: "+result);
- } catch (Exception e) {
- System.err.println("Set Error: "+e.getMessage());
- }
- System.exit(0);
- }
- }