⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmpgw.java

📁 this is the file is used to get the snmp enabled information
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* $Id: snmpgw.src,v 1.4.2.5 2009/01/28 13:23:09 tmanoj Exp $ *//* * @(#)snmpgw.java * Copyright (c) 1996-2009 AdventNet, Inc. All Rights Reserved. * Please read the COPYRIGHTS file for more details. *//** *  snmpgw acts as a gateway between a SNMPv3 management application and a *  SNMP v1/v2c agent system.When you start the snmpgw application, you can *  specify the remote v1 agent address and port number to which requests *  from the SNMPv3 management applications need to be forwarded. You can *  also specify the community string to be used while forwarding requests *  and other session parameters that are appropriate. *  The snmpgw applicaiton also requires the port number on which to listen *  for SNMPv3 requests, the USM security parameters like the user name on *  whose behalf the requests will be accepted, the authentication and privacy *  parameters for the specified user etc. need to be specified.  *  Usage: *     snmpgw [-d] [-v agent_version(v1,v2)] [-c agent_community] [-wc agent_writeCommunity] [-h agent_host] [-p agent_port] [-t timeout] [-r retries] [-a auth_protocol] [-w auth_password] [-s priv_password] ] port engineID user; *     Options: *         -d To get detailed debug output. Currently not a very usefule option *            Default : DEBUG is disabled *         -v version. Used to specify the version of remote host (v1 or v2) *            Default : remote agent version is SNMPv1 *         -c community. Specify the community string used in communication with the v1/v2c remote agent *            Default : public *         -wc writeCommunity. Specify the wite community string used in communication with the v1/v2c remote agent *            Default : null *         -h agent_host. The remote agent host on which the SNMPv1/SNMPv2c agent is running. *            Default : localhost *         -p agent_port. Specify the remote agent port on which the agent listens for SNMPv1/v2c requests *            Default : 161 *         -t timeout. Specify the timeout that is applicable both to the v1/v2c session and the v3 session *         -r retries. Specify the number of retries. Applicable both to the v1/v2c session and the v3 session *         -a authProtocol. The authentication protocol used in communication between the SNMPv3 management *              application and the snmpgw. Default: No Authentication *         -w auth_password. The authentication password used between the SNMPv3 managemnet application and *              the snmpgw application. *         -s priv_password. The privacy password used between the SNMPv3 managemnet application and the *              snmpgw application. *         port. The local UDP port on which the gateway application listens for SNMPv3 requests *         engineID. Specify the engineID of the snmpgw. *         user. Specify the user for whom the security parameters are defined. Currently this is the only user *              for whom the snmpgw will accept requests and forward it to the v1/v2c remote agent. */import com.adventnet.snmp.snmp2.*;import com.adventnet.snmp.snmp2.usm.*;import java.util.*;public class snmpgw extends Thread implements SnmpClient{    SnmpAPI api;    SnmpSession v3_session;    SnmpSession v1_session;    Vector v;    int remoteVersion = 0;    String remoteHost = "localhost";    int remotePort = 161;    int local_port;    byte[] engineID;     private static final int DEBUG_FLAG = 0;    private static final int VERSION_FLAG = 1;    private static final int COMMUNITY_FLAG = 2;    private static final int WRITE_COMMUNITY_FLAG = 3;    private static final int AGENTHOST_FLAG = 4;    private static final int AGENTPORT_FLAG = 5;    private static final int TIMEOUT_FLAG = 6;    private static final int RETRY_FLAG = 7;    private static final int AUTHPROTOCOL_FLAG = 8;    private static final int AUTHPASSWORD_FLAG = 9;    private static final int PRIVPASSWORD_FLAG = 10;    private static final int PRIVPROTOCOL_FLAG = 11;    snmpgw()    {        // Start SNMP API        api = new SnmpAPI();        try        {            Thread.sleep(500);        }        catch (Exception x)        {        }        // Open session and set remote host & port if needed,        v3_session = new SnmpSession(api);        v1_session = new SnmpSession(api);        v = new Vector();    }    public static void main(String args[])    {        snmpgw eserv = new snmpgw();        // Take care of getting options        String usage =        "snmpgw [-d] [-v agent_version(v1,v2)] [-c agent_community] \n" +        "[-wc agent_writeCommunity] [-h agent_host] [-p agent_port] \n" +        "[-t timeout] [-r retries] [-a auth_protocol] [-w auth_password] \n" +        "[-s priv_password] ] [-pp privProtocol(DES/AES-128/AES-192/AES-256/3DES)] port engineID user";        String options[] = { "-d", "-v","-c", "-wc", "-h", "-p", "-t", "-r", "-a", "-w", "-s" ,"-pp" };        String values[] = { "None", null, null, null, null, null, null, null, null, null, null, null };        String userName = null;        int authProtocol = USMUserEntry.NO_AUTH;        String authPassword = null;        String privPassword = null;        int options_flag = 0;	int privProtocol = USMUserEntry.NO_PRIV;        ParseOptions opt = new ParseOptions(args,options,values, usage);        if (opt.remArgs.length<3)        {            opt.usage_error();        }        eserv.local_port = Integer.parseInt(opt.remArgs[0]);        UDPProtocolOptions v3_opt = new UDPProtocolOptions();        v3_opt.setLocalPort(eserv.local_port);        eserv.v3_session.setProtocolOptions(v3_opt);        eserv.engineID = (opt.remArgs[1]).getBytes();        userName = opt.remArgs[2];        if (values[DEBUG_FLAG].equals("Set"))        {            System.out.println("Debug is TRUE");            eserv.api.setDebug( true );        }        if(values[VERSION_FLAG] != null)        {            if(values[VERSION_FLAG].equals("v2"))            {                eserv.remoteVersion = (SnmpAPI.SNMP_VERSION_2C);            }            else if(values[VERSION_FLAG].equals("v1"))            {                eserv.remoteVersion = (SnmpAPI.SNMP_VERSION_1);            }            else            {                System.err.println("Invalid Version Number. Please use v1 or v2");                System.exit(1);            }        }        if (values[COMMUNITY_FLAG] != null)        {            eserv.v1_session.setCommunity( values[COMMUNITY_FLAG] );        }        if (values[WRITE_COMMUNITY_FLAG] != null)        {            eserv.v1_session.setWriteCommunity( values[WRITE_COMMUNITY_FLAG] );        }        try        {            UDPProtocolOptions v1_opt = new UDPProtocolOptions();            if (values[AGENTHOST_FLAG] != null)             {                v1_opt.setRemoteHost(values[AGENTHOST_FLAG]);                eserv.remoteHost = values[AGENTHOST_FLAG];            }            if (values[AGENTPORT_FLAG] != null)             {                eserv.remotePort = Integer.parseInt(values[AGENTPORT_FLAG]);                v1_opt.setRemotePort(eserv.remotePort);            }            eserv.v1_session.setProtocolOptions(v1_opt);            if (values[TIMEOUT_FLAG] != null)             {                eserv.v1_session.setTimeout(Integer.parseInt(values[TIMEOUT_FLAG]));                eserv.v3_session.setTimeout(Integer.parseInt(values[TIMEOUT_FLAG]));            }            if (values[RETRY_FLAG] != null)             {                eserv.v1_session.setRetries(Integer.parseInt(values[RETRY_FLAG]));                eserv.v3_session.setRetries(Integer.parseInt(values[RETRY_FLAG]));            }            if (values[AUTHPROTOCOL_FLAG] != null)             {                if (values[AUTHPROTOCOL_FLAG].compareTo("MD5") == 0)                {                    authProtocol = USMUserEntry.MD5_AUTH;                }                else if (values[AUTHPROTOCOL_FLAG].compareTo("SHA") == 0)                {                    authProtocol = USMUserEntry.SHA_AUTH;                }                else                {                    authProtocol = USMUserEntry.NO_AUTH;                }            }            if (values[AUTHPASSWORD_FLAG] != null)             {                authPassword = values[AUTHPASSWORD_FLAG];            }             if (values[PRIVPASSWORD_FLAG] != null)             {		                   privPassword = values[PRIVPASSWORD_FLAG];            }	    if (values[PRIVPROTOCOL_FLAG] != null)             {                if (values[PRIVPROTOCOL_FLAG].compareTo("DES") == 0)                {                    privProtocol = USMUserEntry.CBC_DES;                }                else if (values[PRIVPROTOCOL_FLAG].compareTo("AES-128") == 0)                {                     privProtocol = USMUserEntry.CFB_AES_128;                }		else if (values[PRIVPROTOCOL_FLAG].compareTo("AES-192") == 0)                {                     privProtocol = USMUserEntry.CFB_AES_192;                }		else if (values[PRIVPROTOCOL_FLAG].compareTo("AES-256") == 0)                {                     privProtocol = USMUserEntry.CFB_AES_256;                }		else if (values[PRIVPROTOCOL_FLAG].compareTo("3DES") == 0)                {                     privProtocol = USMUserEntry.CBC_3DES;                }                else                {                    authProtocol = USMUserEntry.NO_AUTH;                }            }        }        catch(Exception ex)        {            System.err.println(ex.getMessage());            System.exit(2);        }        try        {            eserv.v3_session.open();            eserv.v1_session.open();        }        catch (SnmpException e)        {        }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -