Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
SnmpTrapd_one.java.txt
Package: AdventNetSNMPAPI_4.zip [view]
Upload User: aonuowh
Upload Date: 2021-05-23
Package Size: 35390k
Code Size: 2k
Category:
SNMP
Development Platform:
C/C++
- /* $Id: SnmpTrapd_one.java,v 1.1 2002/06/15 14:42:11 ram Exp $ */
- /*
- * @(#)SnmpTrapd_one.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.snmp2 package of AdventNetSNMP api.
- *
- * The user could run this application by giving the following usage.
- *
- * java SnmpTrapd_one
- *
- * the application will start receiving traps in the port 8001.
- *
- *
- *
- */
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import com.adventnet.snmp.snmp2.*;
- public class SnmpTrapd_one {
- public static void main(String args[]) {
- // Start SNMP API
- SnmpAPI api = new SnmpAPI();
- api.setDebug(true);
- // Open session
- SnmpSession session = new SnmpSession(api);
- // set local port
- SnmpPDU pdu = new SnmpPDU();
- UDPProtocolOptions option = new UDPProtocolOptions("localhost");
- pdu.setProtocolOptions(option);
- pdu.setLocalPort(8001);
- // set community
- session.setCommunity(null);
- // open the session
- try
- {
- session.open();
- }
- catch (SnmpException e )
- {
- System.err.println("Error opening socket: "+e);
- }
- // wait for the trap pdu
- pdu = session.receive(0);
- System.out.println("Waiting to receive traps in the port "+pdu.getLocalPort() +".......");
- while (pdu == null)
- {
- pdu = session.receive(0);
- if(pdu != null)
- {
- if (pdu.getCommand() == SnmpAPI.TRP_REQ_MSG)
- {
- // print the received trap information
- System.out.println("Trap received from: "+pdu.getAddress() +", community: " + pdu.getCommunity());
- System.out.println("Enterprise: " + pdu.getEnterprise());
- System.out.println("Agent: " + pdu.getAgentAddress());
- System.out.println("TRAP_TYPE: " + pdu.getTrapType());
- System.out.println("SPECIFIC NUMBER: " + pdu.getSpecificType());
- System.out.println("Time: " + pdu.getUpTime()+"nVARBINDS:");
- System.out.println(pdu.printVarBinds());
- pdu = null;
- System.out.println("Continues waiting to receive traps in the port "+session.getLocalPort() +".......");
- }
- else
- {
- System.err.println("Non trap PDU received.");
- }
- }
- }
- }
- }