SnmpTrapd.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
- /* $Id: SnmpTrapd.java,v 1.1 2002/06/15 14:40:08 ram Exp $ */
- /*
- * @(#)SnmpTrapd.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- /**
- * This is a tutorial example program for receiving traps using
- * the com.adventnet.snmp.beans package of AdventNetSNMP api.
- *
- * The user could run this application by giving the following usage.
- *
- * java SnmpTrapd
- *
- * the application will start receiving traps in the port 8001.
- *
- *
- *
- */
- import com.adventnet.snmp.beans.*;
- public class SnmpTrapd implements TrapListener {
- // instantiate the trap receiver
- SnmpTrapReceiver trapreceiver = new SnmpTrapReceiver();
- public static void main(String args[]) {
- //instantiate this class to receive trap events
- SnmpTrapd test = new SnmpTrapd();
- test.trapreceiver.setPort(8001);
- test.trapreceiver.addTrapListener(test); //add the listener and register for the trap events
- System.out.println("Waiting to receive traps .......");
- }
-
- public void receivedTrap(TrapEvent trapEvent) {
- //receive traps
- System.out.println("TrapEvent received. ");
- System.out.println("Received a trap from:"+trapEvent.getRemoteHost()+ " in the port "+ trapreceiver.getPort());
- System.out.println("Community is:"+trapEvent.getCommunity());
- System.out.println("Agent Address is:"+trapEvent.getAgentAddress());
- System.out.println("Enterprise OID:"+trapEvent.getEnterprise());
- System.out.println("Trap Variable OID:"+trapEvent.getObjectID(0));
- System.out.println("Continues waiting to receive traps .......");
- }
- }