TrapReceiverApplet.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: TrapReceiverApplet.java,v 1.1 2002/06/15 14:43:56 ram Exp $ */
- /* TrapReceiverApplet.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import java.applet.*;
- import java.io.*;
- import javax.swing.*;
- import com.adventnet.snmp.snmp2.*;
- public class TrapReceiverApplet extends JApplet implements SnmpClient {
-
- JTextArea text;
- SnmpAPI api; // The SNMP API instance
- public void init() {
-
- getContentPane().setLayout(null);
- text = new JTextArea("Waiting to receive trapsn");
- text.setEditable(false);
-
- getContentPane().add(text);
- text.setBounds(30,80,490,85);
-
- }
- public void start() {
-
- api = new SnmpAPI( );
- api.start( );
- api.setDebug(true);
- SnmpSession session = new SnmpSession(api);
- session.setCallbackthread(true);
- session.addSnmpClient( this);
- int port = 8001; // set port to listen for traps
-
- try {
- session.open(this); //Open session for use by the applet
- } catch (SnmpException e) {
- System.err.println("Error opening session:"+e.getMessage());
- System.exit(1);
- }
- SASClient sasClient = session.getSASClient( );
- if (sasClient.isConnected( ) == true) {
- try {
- sasClient.reqTraps(port);
- } catch(IOException ioe) {
- System.err.println("Error " + ioe.getMessage( ));
- }
- text.append("Listening for Traps on port: " + port + "nn");
- }
- else {
- text.append("SAServer not Connected n");
- }
- }
- public boolean callback(SnmpSession session, SnmpPDU pdu, int reqid) {
-
- if (pdu.getCommand() != api.TRP_REQ_MSG)
- System.err.println("Non trap PDU received");
- else
- showStatus("Trap PDU received");
- text.append("Trap received from: "
- +pdu.getRemoteHost() + ", community: " + pdu.getCommunity() + "n");
- return true;
- }
- public void debugPrint(String s) {
-
- System.err.println(s);
- }
- public boolean authenticate(SnmpPDU pdu, String community) {
-
- return true;
-
- }
- }