SnmpGetTable.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: SnmpGetTable.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
- /* SnmpGetTable.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import com.adventnet.snmp.beans.*;
- import com.adventnet.snmp.mibs.*;
- import com.adventnet.snmp.snmp2.*;
- import java.util.*;
- public class SnmpGetTable {
- public static void main(String args[]) {
- if (args.length < 2)
- {
- System.out.println ("Usage : java SnmpGetTable hostname oid ");
- System.exit (0);
- }
- String remoteHost = args[0];
- String oid = args[1];
- SnmpTarget target = new SnmpTarget();
-
- target.setTargetHost(remoteHost);
-
- try {
- target.loadMibs("RFC1213-MIB");
- }catch (Exception ex) {
- }
- MibOperations mibops = target.getMibOperations();
- SnmpOID tableoid = mibops.getSnmpOID(oid); // get table OID
- MibNode tablenode = mibops.getMibNode(tableoid); // get table MIB node
- Vector columns = tablenode.getTableItems();
- String oids[] = new String[columns.size()];
- for (int i=0;i<oids.length;i++) oids[i] = (String)columns.elementAt(i);
-
- target.setObjectIDList(oids);
- String result[][] = target.snmpGetAllList();
-
- System.out.println("Getting table. Table items:");
- StringBuffer sb = new StringBuffer();
- // first print the column names
- for (int i=0;i<oids.length;i++) sb.append(oids[i]+" t");
- sb.append("n");
- // next print each table item
- for (int j=0;j<result.length;j++) { // for each row
- for (int i=0;i<result[j].length;i++) // for each column
- sb.append(result[j][i]+" t");
- sb.append("n");
- }
- System.out.println(sb.toString());
-
- System.exit(0);
-
- }
-
- }