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

📄 snmpvacmconfigure.java

📁 this api for java to do the network managerment of system,i like it ,so share for a
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* $Id: snmpvacmconfigure.src,v 1.3.2.2 2004/03/17 10:05:30 vivek Exp $ *//* * @(#)snmpvacmconfigure.java * Copyright (c) 1996-2004 AdventNet, Inc. All Rights Reserved. * Please read the associated COPYRIGHTS file for more details. *//** * This is an example program used for adding entries to * the VACM tables, namely "vacmSecurityToGroupTable", * "vacmAccessTable" and "vacmViewTreeFamilyTable". */import java.util.StringTokenizer;import com.adventnet.snmp.snmp2.*;import com.adventnet.snmp.snmp2.vacm.*;import com.adventnet.snmp.snmp2.usm.*;public class snmpvacmconfigure{    static private final int CREATEACCESS       = 1;    static private final int DELETEACCESS       = 2;    static private final int CREATESEC2GROUP    = 3;    static private final int DELETESEC2GROUP    = 4;    static private final int CREATEVIEW         = 5;    static private final int DELETEVIEW         = 6;    static private final int HELP               = 7;    static private final int QUIT               = 8;    private final int CREATE_AND_GO         = 4;    private final String securityToGroupTableEntry = ".1.3.6.1.6.3.16.1.2.1.";    private final String vacmAccessEntry = ".1.3.6.1.6.3.16.1.4.1.";    private final String vacmFamilyEntry = ".1.3.6.1.6.3.16.1.5.2.1.";    private String params;    static private final String accessHelp ="\n\n" +"------------------------------------------------------------------------\n" +"                           \"vacmAccessTable\"\n" +"------------------------------------------------------------------------\n" +"S.No ColumnName               Data Type     Size      Possible values\n" +"------------------------------------------------------------------------\n" +"1.   vacmGroupName            OCTET STRING  1 .. 32          -\n" +"2.   vacmAccessContextPrefix  OCTET STRING  0 .. 32          -\n" +"3.   vacmAccessSecurityModel  INTEGER         -       0 .. 2147483647\n" +"4.   vacmAccessSecurityLevel  INTEGER         -       1(noAuthNoPriv)\n" +"                                              -       2(authNoPriv)\n" +"                                              -       3(authPriv)\n" +"5.   vacmAccessContextMatch   INTEGER         -       1(exact)\n" +"                                              -       2(prefix)\n" +"6.   vacmAccessReadViewName   OCTET STRING  0 .. 32          -\n" +"7.   vacmAccessWriteViewName  OCTET STRING  0 .. 32          -\n" +"8.   vacmAccessNotifyViewName OCTET STRING  0 .. 32          -\n" +"------------------------------------------------------------------------\n";        static private final String securityToGroupHelp ="\n\n" +"------------------------------------------------------------------------\n" +"                           \"vacmSecurityToGroupTable\"\n" +"------------------------------------------------------------------------\n" +"S.No ColumnName                     Data Type     Size      Possible values\n" +"------------------------------------------------------------------------\n" +"1.   vacmSecurityModel              INTEGER         -       0 .. 2147483647\n"+"2.   vacmSecurityName               OCTET STRING  1 .. 32          -\n" +"3.   vacmGroupName                  OCTET STRING  1 .. 32          -\n" +"4.   vacmSecurityToGroupStorageType INTEGER         -       1(other)\n" +"                                                            2(volatile)\n" +"                                                            3(nonVolatile)\n" +"                                                            4(permanent)\n" +"                                                            5(readOnly)\n" +"------------------------------------------------------------------------\n";    static private final String familyTableHelp ="\n\n" +"------------------------------------------------------------------------------\n" +"                           \"vacmViewTreeFamilyTable\"\n" +"------------------------------------------------------------------------------\n" +"S.No ColumnName                  Data Type          Size      Possible values\n" +"------------------------------------------------------------------------------\n" +"1.   vacmViewTreeFamilyViewName  OCTET STRING       1 .. 32          -\n" +"2.   vacmViewTreeFamilySubtree   OBJECT IDENTIFIER    -              -\n" +"3.   vacmViewTreeFamilyMask      OCTET STRING       0 .. 16          -\n" +"------------------------------------------------------------------------------\n" ;    private SnmpAPI api;    private SnmpSession session;        private int timeout;    private int retries;    private String remoteHost;    private int remotePort;    private int version;    private String contextName;    private String userName;    private String authPassword;    private int authProtocol;    private String privPassword;    private String optionString;    private int action;    private String helpNumber;    public snmpvacmconfigure() throws SnmpException    {        api = new SnmpAPI();        session = new SnmpSession(api);        session.open();        timeout = 5000;        retries = 0;        remoteHost = null;        remotePort = 161;        version = 0;        contextName = null;        userName = null;        authPassword = null;        authProtocol = USMUserEntry.NO_AUTH;        privPassword = null;        params = null;        optionString =         "\n\n---------------------------------------\n" +        "1. createAccess\n" +        "2. deleteAccess\n" +        "3. createSec2Group\n" +        "4. deleteSec2Group\n" +        "5. createView\n" +        "6. deleteView\n" +        "7. Help\n" +        "8. Quit\n" +        "Enter a Choice :";        helpNumber = "";    }    public void setRemoteHost(String host)    {        this.remoteHost = host;    }    public void setRemotePort(int remotePort)    {        this.remotePort = remotePort;    }        public void setTimeout(int timeout)    {        this.timeout = timeout;    }    public void setRetries(int retries)    {        this.retries = retries;    }    public void setVersion(int version)    {        this.version = version;    }    public void setContextName(String contextName)    {        this.contextName = contextName;    }    public void setUserName(String userName)    {        this.userName = userName;    }    public void setAuthPassword(String authPassword)    {        this.authPassword = authPassword;    }    public void setAuthProtocol(int authProtocol)    {        this.authProtocol = authProtocol;    }    public void setPrivPassword(String privPassword)    {        this.privPassword = privPassword;    }    public void initDatabase(String driver, String url,    String user, String password)throws SnmpException    {        try        {            api.initJdbcParams(driver, url, user, password);        }        catch(Exception exp)        {            throw new SnmpException(exp.toString());        }    }    public void createUSMEntry() throws SnmpException    {        if(userName == null || userName.length() == 0)        {            throw new SnmpException("Invalid UserName.");        }        if(authPassword != null && authProtocol == USMUserEntry.NO_AUTH)        {            throw new SnmpException(            "Specify the authProtocol if authPassword is specified.");        }        if(privPassword != null && authPassword == null)        {            throw new SnmpException(            "An user cannot be \"noAuth,Priv\", " +            "hence specify the authPassword");        }        USMUtils.init_v3_params(userName, authProtocol, authPassword,            privPassword, remoteHost, remotePort, session);        System.out.println("\n\nSuccessfully created the USM entry for " +            remoteHost + ":" + remotePort + ":" + userName + ".");    }    public void close()    {        session.close();        api.close();    }    public void processConfiguration()    {        int action = -1;        String line = "";        do        {            try            {                helpNumber = "";                System.out.print(optionString);                StringTokenizer st = new StringTokenizer(readLine());                int tokens = st.countTokens();                line = st.nextToken();                if(tokens > 1)                {                    helpNumber = st.nextToken();                }                try                {                    action = Integer.parseInt(line);                    if(!isValidOption(action))                    {                        System.out.println("\nInvalid option. " + action);                        continue;                    }                    performAction(action);                }                catch(NumberFormatException exp)                {                    System.out.println("Invalid Option. " + line);                    continue;                }            }            catch(Exception exp)            {            }        }while(action != QUIT);    }    private void performAction(int action)    {        switch(action)        {            case CREATEACCESS:            {                createAccess();                break;            }            case DELETEACCESS:            {                deleteAccess();                break;            }            case CREATESEC2GROUP:            {                createSecurityToGroup();                break;            }            case DELETESEC2GROUP:            {                deleteSecurityToGroup();                break;            }            case CREATEVIEW:            {                createView();                break;            }            case DELETEVIEW:            {                deleteView();                break;            }            case HELP:            {                help();                break;            }        }    }    private SnmpPDU getSnmpPDU()    {        SnmpPDU pdu = new SnmpPDU();        UDPProtocolOptions pdu_opt = new UDPProtocolOptions(remoteHost, remotePort);        pdu.setProtocolOptions(pdu_opt);        pdu.setVersion(version);        pdu.setCommand(api.SET_REQ_MSG);        if(version == SnmpAPI.SNMP_VERSION_3)        {            if(userName != null)            {                pdu.setUserName(userName.getBytes());            }            if(contextName != null)            {                pdu.setContextName(contextName.getBytes());            }        }        return pdu;    }    private void createAccess()    {        try        {            if(params == null)            {                System.out.println(                "Please enter the following in a single line " +                "seperated by space:\n" +                "GROUPNAME PREFIX SECURITYMODEL SECURITYLEVEL MATCH " +                "READ WRITE NOTIFY ");            //  + "STORAGE_TYPE");            }            String s = (params == null)? readLine() : params;            StringTokenizer st = new StringTokenizer(s, " ");            String groupName = st.nextToken();            String prefix = st.nextToken();            int model = Integer.parseInt(st.nextToken());            int level = Integer.parseInt(st.nextToken());

⌨️ 快捷键说明

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