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

📄 snmpinquisitor.java

📁 snmp inquistor Pour la communication avec les agents SNMP on utilise un package Java open source
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//Listing 2: SNMPInquisitor.java source code/* * SNMP Inquisitor * * Copyright (C) 2000, Jonathan Sevy <jsevy@cs.drexel.edu> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * */  import java.util.*;import java.net.*;import java.awt.*;import javax.swing.*;import javax.swing.border.*;import javax.swing.plaf.*;import java.awt.event.*;import java.io.*;import java.math.*;//import com.adventnet.snmp.*;import snmp.*;   public class SNMPInquisitor extends JFrame                            implements ActionListener, Runnable{    JButton getDataButton, getTreewalkDataButton, setValueButton;    JButton clearButton;    JTextArea messagesArea;    JScrollPane messagesScroll;    JTextField hostIDField, communityField, OIDField, valueField;    JLabel authorLabel, hostIDLabel, communityLabel, OIDLabel, valueLabel;    JComboBox valueTypeBox;    MenuBar theMenubar;    Menu fileMenu;    MenuItem quitItem;    Thread treewalkThread;         SNMPv1CommunicationInterface comInterface;    String community;    InetAddress hostAddress;    int version;     // WindowCloseAdapter to catch window close-box closings    private class WindowCloseAdapter extends WindowAdapter    {        public void windowClosing(WindowEvent e)        {            System.exit(0);        }    };     public SNMPInquisitor()    {        treewalkThread = new Thread(this);        setUpDisplay();    }      private void setUpDisplay()    {         this.setTitle("SNMP Inquisitor");         this.getRootPane().setBorder(new BevelBorder(BevelBorder.RAISED));        // set fonts to smaller-than-normal size, for compaction!        UIManager manager = new UIManager();        FontUIResource appFont = new FontUIResource("SansSerif", Font.PLAIN, 10);        UIDefaults defaults = manager.getLookAndFeelDefaults();        Enumeration keys = defaults.keys();        while (keys.hasMoreElements())        {            String nextKey = (String)(keys.nextElement());            if ((nextKey.indexOf("font") > -1) || (nextKey.indexOf("Font") > -1))            {                manager.put(nextKey, appFont);            }        }         // add WindowCloseAdapter to catch window close-box closings        addWindowListener(new WindowCloseAdapter());         theMenubar = new MenuBar();        this.setMenuBar(theMenubar);        fileMenu = new Menu("File");        quitItem = new MenuItem("Quit");        quitItem.setActionCommand("quit");        quitItem.addActionListener(this);        fileMenu.add(quitItem);        theMenubar.add(fileMenu);         hostIDLabel = new JLabel("Device address:");        hostIDField = new JTextField(20);        hostIDField.setText("10.0.1.1");        hostIDField.setEditable(true);        OIDLabel = new JLabel("OID:");        OIDField = new JTextField(20);        OIDField.setEditable(true);        valueLabel = new JLabel("Value (for Set):");        valueField = new JTextField(20);        valueField.setEditable(true);        communityLabel = new JLabel("Community:");        communityField = new JTextField(20);        communityField.setText("public");        communityField.setEditable(true);         authorLabel = new JLabel(" Version 1.1        J. Sevy, January 2001 ");        authorLabel.setFont(new Font("SansSerif", Font.ITALIC, 8));         getDataButton = new JButton("Get OID value");        getDataButton.setActionCommand("get data");        getDataButton.addActionListener(this);        setValueButton = new JButton("Set OID value");        setValueButton.setActionCommand("set value");        setValueButton.addActionListener(this);        getTreewalkDataButton = new JButton("Get all OID values");        getTreewalkDataButton.setActionCommand("get treewalk data");        getTreewalkDataButton.addActionListener(this);        clearButton = new JButton("Clear responses");        clearButton.setActionCommand("clear messages");        clearButton.addActionListener(this);        messagesArea = new JTextArea(10,60);        messagesScroll = new JScrollPane(messagesArea);        valueTypeBox = new JComboBox();        valueTypeBox.addItem("SNMPInteger");        valueTypeBox.addItem("SNMPCounter32");        valueTypeBox.addItem("SNMPCounter64");        valueTypeBox.addItem("SNMPGauge32");        valueTypeBox.addItem("SNMPOctetString");        valueTypeBox.addItem("SNMPIPAddress");        valueTypeBox.addItem("SNMPNSAPAddress");        valueTypeBox.addItem("SNMPObjectIdentifier");        valueTypeBox.addItem("SNMPTimeTicks");        valueTypeBox.addItem("SNMPUInteger32");          // now set up display        // set params for layout manager        GridBagLayout  theLayout = new GridBagLayout();        GridBagConstraints c = new GridBagConstraints();        c.gridwidth = 1;        c.gridheight = 1;        c.fill = GridBagConstraints.NONE;        c.ipadx = 0;        c.ipady = 0;        c.insets = new Insets(2,2,2,2);        c.anchor = GridBagConstraints.CENTER;        c.weightx = 0;        c.weighty = 0;         JPanel buttonPanel = new JPanel();        buttonPanel.setLayout(theLayout);        c.gridx = 1;        c.gridy = 1;        theLayout.setConstraints(getDataButton, c);        buttonPanel.add(getDataButton);        c.gridx = 2;        c.gridy = 1;        theLayout.setConstraints(getTreewalkDataButton, c);        buttonPanel.add(getTreewalkDataButton);        c.gridx = 3;        c.gridy = 1;        theLayout.setConstraints(setValueButton, c);        buttonPanel.add(setValueButton);         JPanel hostPanel = new JPanel();        hostPanel.setLayout(theLayout);        c.gridx = 1;        c.gridy = 1;        theLayout.setConstraints(hostIDLabel, c);        hostPanel.add(hostIDLabel);        c.gridx = 2;        c.gridy = 1;        theLayout.setConstraints(hostIDField, c);        hostPanel.add(hostIDField);        c.gridx = 1;        c.gridy = 2;        theLayout.setConstraints(communityLabel, c);        hostPanel.add(communityLabel);        c.gridx = 2;        c.gridy = 2;        theLayout.setConstraints(communityField, c);        hostPanel.add(communityField);          JPanel oidPanel = new JPanel();        oidPanel.setLayout(theLayout);        c.gridx = 1;        c.gridy = 1;        theLayout.setConstraints(OIDLabel, c);        oidPanel.add(OIDLabel);        c.gridx = 2;        c.gridy = 1;        theLayout.setConstraints(OIDField, c);        oidPanel.add(OIDField);        c.gridx = 1;        c.gridy = 2;        theLayout.setConstraints(valueLabel, c);        oidPanel.add(valueLabel);        c.gridx = 2;        c.gridy = 2;        theLayout.setConstraints(valueField, c);        oidPanel.add(valueField);        c.gridx = 3;        c.gridy = 2;        theLayout.setConstraints(valueTypeBox, c);        oidPanel.add(valueTypeBox);         c.gridwidth = 1;        c.anchor = GridBagConstraints.CENTER;          JPanel messagesPanel = new JPanel();        messagesPanel.setLayout(theLayout);        c.gridx = 1;        c.gridy = 1;        c.anchor = GridBagConstraints.WEST;        JLabel messagesLabel = new JLabel("Responses:");        theLayout.setConstraints(messagesLabel, c);        messagesPanel.add(messagesLabel);        c.gridx = 2;        c.gridy = 1;        c.anchor = GridBagConstraints.EAST;        theLayout.setConstraints(clearButton, c);        messagesPanel.add(clearButton);        c.fill = GridBagConstraints.BOTH;        c.gridx = 1;        c.gridy = 2;        c.gridwidth = 2;        c.weightx = .5;        c.weighty = .5;        c.anchor = GridBagConstraints.CENTER;        theLayout.setConstraints(messagesScroll, c);        messagesPanel.add(messagesScroll); 

⌨️ 快捷键说明

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