Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
FetchTable.java.txt
Package: AdventNetSNMPAPI_4.zip [view]
Upload User: aonuowh
Upload Date: 2021-05-23
Package Size: 35390k
Code Size: 2k
Category:
SNMP
Development Platform:
C/C++
- * @(#)FetchTable.java
- * Copyright (c) 1996-2003 AdventNet, Inc. 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 the sample table with column ids .1.3.6.1.4.1.2.2.1.1,
- * .1.3.6.1.4.1.2.2.1.2, .1.3.6.1.4.1.2.2.1.3, by using
- * com.adventnet.snmp.snmp2 package of AdventNetSNMP API.
- *
- * The user could run this application by giving the following usage.
- *
- * java FetchTable
- *
- *
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import com.adventnet.snmp.snmp2.*;
- public class FetchTable {
- 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 Get request PDU
- SnmpPDU pdu = new SnmpPDU();
- UDPProtocolOptions option = new UDPProtocolOptions("localhost");
- pdu.setProtocolOptions(option);
- // get the OIDs
- SnmpOID[] oids = new SnmpOID[3];
- oids[0]=new SnmpOID(".1.3.6.1.4.1.2.2.1.1");
- oids[1]=new SnmpOID(".1.3.6.1.4.1.2.2.1.2");
- oids[2]=new SnmpOID(".1.3.6.1.4.1.2.2.1.3");
- // Send PDU and receive response PDU
- for(int i=0;i<3;i++)
- {
- pdu.addnull(oids[i]);
- }
- SnmpOID rootoid = new SnmpOID(".1.3.6.1.4.1.2.2.1.");
- String root = rootoid.toString();
- boolean comeOut = false;
- int rowCount = 1;
- while(!comeOut)
- {
- SnmpPDU result = session.syncSend(pdu);
- if(result == null)
- {
- System.out.println("Request timed out!");
- comeOut = true;
- break;
- }
- int size = pdu.getVariableBindings().size();
- for(int i=0;i<size;i++)
- {
- if(pdu.getObjectID(i).toString().startsWith(root))
- {
- comeOut = true;
- break;
- }
- }
- if(i == size)
- {
- System.out.println("ROW " + (rowCount++));
- System.out.println(result.printVarBinds() + "n" );
- }
- pdu.setCommand(SnmpAPI.GETNEXT_REQ_MSG);
- }
- // close session
- session.close();
- // close api thread
- api.close();
- }
- }