SendTrap.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:1k
- /* $Id: SendTrap.java,v 1.1 2002/06/15 14:41:18 ram Exp $ */
- /*
- * @(#)SendTrap.java
- * Copyright (c) 1996-2001 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 send a
- * v1 Trap message using com.adventnet.snmp.beans packages of AdventNetSNMP2 api.
- *
- * java SendTrap
- *
- */
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import com.adventnet.snmp.beans.*;
- public class SendTrap {
- public static void main(String args[]) {
- // instantiate SNMP target bean
- SnmpTarget target = new SnmpTarget();
- target.settargetHost("hostname");
- //set the Target Port on which the target host would be listening to receive traps.
- target.setTargetPort(162);
- //Set the SnmpOID
- target.setObjectID("1.5.0");
- //Send v1 trap
- String values[] = {"testing"};
- try
- {
- // use SnmpTarget method to send trap with specified OID/values
- target.snmpSendTrap("1.2.0", "localhost", 0, 6, 1000, values);
- System.out.println("Response PDU received from " +target.getTargetHost()+ ", community: " + target.getCommunity());
-
- }
- catch (Exception e)
- {
- System.err.println("Error Sending Trap: "+e.getMessage());
- }
- System.exit(0);
- }
- }