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

SNMP编程

开发平台:

C/C++

  1. /* $Id: SnmpTrapd.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
  2. /*
  3.  * @(#)SnmpTrapd.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 for receiving traps using 
  9.  * the com.adventnet.snmp.beans package of AdventNetSNMP api.
  10.  *
  11.  * The user could run this application by giving the following usage.
  12.  *  
  13.  * java SnmpTrapd
  14.  *
  15.  * the application will start receiving traps in the port 8001.
  16.  * 
  17.  *
  18.  *
  19.  */
  20. import com.adventnet.snmp.beans.*;
  21. public  class SnmpTrapd implements TrapListener {
  22.         // instantiate the trap receiver 
  23.         SnmpTrapReceiver trapreceiver = new SnmpTrapReceiver();
  24.         public static void main(String args[])         {
  25.     //instantiate this class to receive trap events
  26.         SnmpTrapd test = new SnmpTrapd();
  27. test.trapreceiver.setPort(8001);
  28.                 test.trapreceiver.addTrapListener(test); //add the listener and register for the trap events
  29. System.out.println("Waiting to receive traps .......");
  30.         }
  31.         
  32.         public void receivedTrap(TrapEvent trapEvent)         {
  33.     //receive traps
  34.         System.out.println("TrapEvent received. ");
  35. System.out.println("Received a trap from:"+trapEvent.getRemoteHost()+ " in the port "+ trapreceiver.getPort());
  36.                 System.out.println("Community is:"+trapEvent.getCommunity());
  37. System.out.println("Agent Address is:"+trapEvent.getAgentAddress());
  38. System.out.println("Enterprise OID:"+trapEvent.getEnterprise());
  39. System.out.println("Trap Variable OID:"+trapEvent.getObjectID(0));
  40.                 System.out.println("Continues waiting to receive traps ......."); 
  41.         } 
  42. }