Sasexample.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:1k
- /*
- * @(#)Sasexample.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import java.applet.*;
- import java.awt.*;
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import com.adventnet.snmp.snmp2.*;
- public class Sasexample extends Applet {
- // to print the results
- Label label = new Label();
- public void init(){
-
- // start SNMP API
- SnmpAPI api;
- api = new SnmpAPI();
- api.start();
-
- SnmpSession session = new SnmpSession(api);
- //open session for use by the applet
- try {
- session.open(this);
- } catch (SnmpException e ) {
- System.err.println("Error opening socket: "+e);
- }
- // set remote host - make sure your agent is running
- session.setPeername("localhost");
- // add OID
- SnmpOID oid = new SnmpOID(".1.3.6.1.2.1.1.1.0");
- // build GET request
- SnmpPDU pdu = new SnmpPDU();
- pdu.setCommand( api.GET_REQ_MSG );
- pdu.addNull(oid);
- try {
- pdu = session.syncSend(pdu);
- } catch (SnmpException e) {
- System.err.println("Error sending SNMP request: "+e);
- }
- // print the response pdu
- add(label);
- label.setText(pdu.printVarBinds());
-
- // close session
- session.close();
- //stop api thread
- api.close();
- }
- }