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
viewTrap.java.txt
Package: AdventNetSNMPAPI_4.zip [view]
Upload User: aonuowh
Upload Date: 2021-05-23
Package Size: 35390k
Code Size: 5k
Category:
SNMP
Development Platform:
C/C++
- /* $Id: viewTrap.java,v 1.4 2002/09/09 05:45:08 parasuraman Exp $ */
- /*
- * viewTrap.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- /** The import clauses */
- import java.lang.*;
- import java.io.*;
- import java.util.*;
- import java.awt.*;
- import java.applet.*;
- import java.net.URL;
- import java.io.InputStream;
- import com.adventnet.snmp.snmp2.*;
- import com.adventnet.management.transport.TransportException;
- import com.adventnet.snmp.mibs.*;
- public class viewTrap extends Applet implements SnmpClient {
- /** Some of the widgets in the main applet window. */
- TextArea text;
- Label header;
- /** The SNMP API instance */
- SnmpAPI api;
- /** The applets init method sets up the GUI */
- public void init() {
- /** The font to be used */
- Font fontb = new Font("Helvetica",Font.BOLD,16);
- // Now the GUI elements
- header = new Label("INCOMING TRAPS");
- header.setFont(fontb);
- text = new TextArea("Startnn");
- text.setEditable(false);
- text.setFont(fontb);
- setLayout(new BorderLayout());
- add("North", header);
- add("Center", text);
- } // end of init
- /** The start method, used when applet is started */
- public void start() {
- // Start SNMP API
- api = new SnmpAPI();
- api.setDebug(true);
- String mib = getParameter("mib");
- if (mib != null){
- text.appendText("Loading MIB file: " + mib + "n");
- // Loading MIBS - For addtional mibs to load please modify yourself.
- MibOperations mibOps = new MibOperations();
- try {
- mibOps.loadMibModules(mib);
- }
- catch(Exception e) {
- System.err.println(e.getMessage());
- }
- }
- // Open session
- SnmpSession session = new SnmpSession(api);
- session.setSASProtocol(2);
- session.setCallbackthread(true);
- session.addSnmpClient( this);
- // set port to listen for traps
- int port = 162;
- if (getParameter("port") != null)
- try {
- port = Integer.parseInt(getParameter("port"));
- }
- catch (NumberFormatException ex) {
- System.err.println("Invalid Integer Arg"); }
- // Open the session
- try { session.open(this); }
- catch (SnmpException e) {
- System.err.println(e);
- System.exit(1);
- }
- // set the port to listen for traps
- if(session.getSASClient() != null)
- try {
- session.getSASClient().reqTraps(port);
- }
- catch(IOException io){
- //System.err.println("Error "+io.getMessage());
- }
- catch(TransportException io) {
- System.err.println("Error "+io.getMessage()); }
- text.appendText("Listening for Traps on port " + port + "nn");
- } // end of start()
- /** The stop method, used when applet is no longer on
- screen */
- public void stop() {
- if (api == null) return;
- api.close();
- api = null;
- }
- public boolean callback(SnmpSession session, SnmpPDU pdu,
- int reqid) {
- if (pdu.getCommand() != api.TRP_REQ_MSG)
- System.err.println("Non trap PDU received, printing anyway.");
- text.appendText("Trap received from: "
- +pdu.getRemoteHost() + ", community: " + pdu.getCommunity() + "n");
- if(pdu.getEnterprise() != null){
- text.appendText("Enterprise: " + pdu.getEnterprise() + "n");
- }
- String agent_ip_addr = SnmpIpAddress.netbToString(pdu.getAgentAddress().getAddress()) ;
- text.appendText("Agent: " + agent_ip_addr + "n");
- int host_timeout=26000;
- text.appendText("TRAP_TYPE: " + pdu.getTrapType() + "n");
- text.appendText("SPECIFIC NUMBER: " + pdu.getSpecificType()+ "n");
- text.appendText("Time: " + pdu.getUpTime() +"nVARBINDS:n");
- for (Enumeration e = pdu.getVariableBindings().elements() ;
- e.hasMoreElements() ;)
- text.appendText(((SnmpVarBind)
- e.nextElement()).toTagString() + "n");
- text.appendText("nn"); // a blank line between traps
- return true; // need no more processing
- } // end of callback()
- /** We need to implement the other methods in the
- SnmpClient interface */
- public void debugPrint(String s) {
- System.err.println(s);
- }
- public boolean authenticate(SnmpPDU pdu, String community)
- {
- return true;
- }
- }