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
SnmpSendTrap_one.java.txt
Package: AdventNetSNMPAPI_4.zip [view]
Upload User: aonuowh
Upload Date: 2021-05-23
Package Size: 35390k
Code Size: 3k
Category:
SNMP
Development Platform:
C/C++
- /* $Id: SnmpSendTrap_one.java,v 1.1 2002/06/15 14:42:11 ram Exp $ */
- /*
- * @(#)SnmpSendTrap_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 to explain how to write an application to send a
- * v1 Trap message using com.adventnet.snmp.snmp2 package of AdventNetSNMP2 api.
- *
- * The user could run this application by giving the following usage.
- *
- * java SnmpSendTrap hostname
- *
- * where
- *
- * hostname is the RemoteHost (agent).The Format is string without double qoutes/IpAddress.
- *
- *
- *
- *
- */
- import java.lang.*;
- import java.util.*;
- import java.net.*;
- import com.adventnet.snmp.snmp2.*;
- public class SnmpSendTrap_one {
- public static void main(String args[]) {
- if( args.length < 1)
- {
- System.out.println("Usage : java SnmpSendTrap_one hostname ");
- System.exit(0);
- }
- // Take care of getting the hostname
- String remoteHost = args[0];
- // Start SNMP API
- SnmpAPI api;
- api = new SnmpAPI();
- api.start();
- api.setDebug(true);
- // Open session
- SnmpSession session = new SnmpSession(api);
- // set remote host
- session.setPeername(remoteHost);
- // set remote port
- session.setRemotePort(8001);
- //open the session
- try {
- session.open();
- } catch (SnmpException e ) {
- System.err.println("Error opening socket: "+e);
- }
- // Build SNMPv1 Trap PDU
- SnmpPDU pdu = new SnmpPDU();
- pdu.setCommand( api.TRP_REQ_MSG );
- // fill in v1 trap PDU fields
- try {
- pdu.setEnterprise(new SnmpOID("1.2.0"));
- pdu.setAgentAddress(InetAddress.getByName("192.168.1.40"));
- pdu.setTrapType(0);
- pdu.setSpecificType(6);
- pdu.setUpTime(1000);
- }
- catch (Exception ex) {
- System.err.println("error in one or more required fields: "+ex);
- }
- // add OID
- SnmpOID oid = new SnmpOID("1.5.0");
- // set the type
- byte dataType;
- dataType = SnmpAPI.STRING;
- String value = "testing from simple program";
- // create SnmpVar instance for the value and the type
- SnmpVar var = null;
- try {
- var = SnmpVar.createVariable( value, dataType );
- }
- catch(SnmpException e){
- System.err.println("Cannot create variable: " + oid + " with value: " + value);
- return;
- }
- //create varbind
- SnmpVarBind varbind = new SnmpVarBind(oid, var);
- // add variable binding
- pdu.addVariableBinding(varbind);
- // send PDU
- try {
- session.send(pdu);
- } catch (SnmpException e) {
- System.err.println("Sending PDU"+e.getMessage());
- }
- System.exit(0);
- }
- }