SnmpGetNext.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /* $Id: SnmpGetNext.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
  2. /*
  3.  * @(#)SnmpGetNext.java
  4.  * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the associated COPYRIGHTS file for more details.
  6.  */
  7. /**
  8.  * This is a tutorial example program to explain how to write an application to do
  9.  * the basic SNMP operation GET NEXT using com.adventnet.snmp.beans package of
  10.  * AdventNetSNMP api.
  11.  *
  12.  * The user could run this application by giving the following usage.
  13.  *  
  14.  * java SnmpGetNext hostname OID [OID]
  15.  *
  16.  * where 
  17.  *
  18.  * hostname is the RemoteHost (agent).The Format is string without double qoutes/IpAddress.
  19.  * OID is the Object Identifier. Multiple OIDs can also be given.
  20.  * The entire OID can be given or it can be given in the form of 1.1.0.
  21.  * If the oid is not starting with a dot (.) it will be prefixed by .1.3.6.1.2.1 .
  22.  * So the entire OID of 1.1.0 will become .1.3.6.1.2.1.1.1.0 .
  23.  *
  24.  * Example usage:
  25.  *
  26.  * java SnmpGetNext adventnet 1.1.0 1.2.0 1.3.0 1.4.0
  27.  *
  28.  */
  29. import com.adventnet.snmp.beans.*;
  30. public class SnmpGetNext {
  31. public static void main(String args[]) {
  32.       if( args.length < 2)
  33. {
  34. System.out.println("Usage : java SnmpGetNext hostname OID ");
  35. System.exit(0);
  36. }
  37.         
  38.         // Take care of getting the hostname and the OID
  39. String remoteHost = args[0];
  40.         String OID = args[1];      
  41. // Instantiate the SnmpTarget bean
  42. SnmpTarget target = new SnmpTarget();
  43. //set host and other parameters
  44. target.setTargetHost(remoteHost);  
  45. String oids[] = new String [args.length - 1];
  46. for (int i=1; i<args.length; i++) oids[i-1] = args[i];
  47. // multiple OID's can be processed
  48. target.setObjectIDList(oids);  
  49.     
  50. // do the SNMP GET NEXT  operation
  51. String result[] = target.snmpGetNextList();
  52.     
  53. // print the results
  54. for (int i=0;i<oids.length;i++) { 
  55.     System.out.println("OBJECT ID: "+target.getObjectID(i));
  56.     System.out.println("Response: "+result[i]);
  57. }
  58. System.exit(0);
  59.     }
  60. }