日期:2014-05-19  浏览次数:20683 次

java 基于SNMP/MIB的网络数据获取系统设计与实现
/**************************************************************
*
* MibExplorer.java
*
* This application allows you view the MIB tree you loaded,
* get value from,or set value to some equipments in networks
* that are running SNMP agent process.
*
* Author: HEJIE
* Parameter: None
* Returns: None
* Creation date: 1/3/2007
* LastUpdate: None
*
**************************************************************/

import com.adventnet.snmp.beans.*;
import com.adventnet.snmp.ui.*;
import com.adventnet.snmp.mibs.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MibExplorer extends JFrame implements ActionListener
{
Container contentPane=getContentPane();
JMenuBar menub=new JMenuBar();
JMenu files=new JMenu("File");
JMenu opera=new JMenu("Operation");
JMenu help=new JMenu("Help");
JMenuItem save=new JMenuItem("Save Result As...");
JMenuItem exit=new JMenuItem("Exit");
JMenuItem get=new JMenuItem("Get");
JMenuItem getNext=new JMenuItem("GetNext");
JMenuItem set=new JMenuItem("Set");
JMenuItem about=new JMenuItem("About");

JLabel hostL=new JLabel("Host:");
JLabel portL=new JLabel("Port:");
JLabel communityL=new JLabel("Community:");
JLabel writeCommL=new JLabel("Write Community:");
JLabel setValueL=new JLabel("Set Value:");
JLabel oidL=new JLabel("ObjectID:");
JLabel descrL=new JLabel("Descricption:");
JTextField host=new JTextField("127.0.0.1");
JTextField port=new JTextField("161");
JPasswordField community=new JPasswordField("public");
JPasswordField writeComm=new JPasswordField("public");
JTextField setValue=new JTextField();
JTextField oid=new JTextField(".1.3.6.1.2.1.1.1.0");
JTextArea descr=new JTextArea();
JButton getB=new JButton("Get");
JButton getNextB=new JButton("GetNext");
JButton setB=new JButton("set");
JButton getTableB=new JButton("GetTable");
JButton clear=new JButton("Clear");
JTextArea mess=new JTextArea();


MibExplorer()
{
super("--Simple MibExplorer--");
int x,y;
Dimension size=Toolkit.getDefaultToolkit().getScreenSize();
x=(size.width-750)/2;
y=(size.height-500)/2;
setSize(750,500);
setLocation(x,y);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//setVisible(true);
}

void init()
{
//主界面初始化
files.setMnemonic('F');
opera.setMnemonic('O');
help.setMnemonic('H');
save.setMnemonic('S');
exit.setMnemonic('X');
get.setMnemonic('G');
getNext.setMnemonic('N');
set.setMnemonic('E');
about.setMnemonic('A');
//为控件添加助记符
save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
get.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,InputEvent.CTRL_MASK));
getNext.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));
set.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,InputEvent.CTRL_MASK));
//为控件添加快捷键
files.add(save);
files.addSeparator();
files.add(exit);
opera.add(get);
opera.add(getNext);
opera.addSeparator();
opera.add(set);
help.add(about);
menub.add(files);
menub.add(opera);
menub.add(help);
setJMenuBar(menub);

save.addActionListener(t