// Home | Go Back //
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.ireasoning.protocol.snmp.*;
import com.ireasoning.protocol.*;
public class SnmpApplet extends Applet implements ActionListener, Listener
{
TextArea _textarea;
TextField _subtreeOid;
public void init()
{
setLayout(new BorderLayout());
Panel p = new Panel();
p.setLayout(new BorderLayout());
p.add(new Label("Subtree OID:"), BorderLayout.WEST);
_subtreeOid = new TextField(".1.3");
p.add(_subtreeOid, BorderLayout.CENTER);
add(p, BorderLayout.NORTH);
_textarea = new TextArea("", 200, 120);
add(_textarea, BorderLayout.CENTER);
Button btn = new Button("Start");
add(btn, BorderLayout.SOUTH);
btn.addActionListener(this);
}
public void handleMsg(Object msgSender, Msg msg)
{
SnmpPdu pdu = (SnmpPdu)msg;
if(pdu.hasMore())
{
SnmpVarBind[] varbinds = pdu.getVarBinds();
for (int i = 0; i < varbinds.length ; i++)
{
_textarea.append("" + varbinds[i] + "\n\n");
}
}
}
public void actionPerformed(ActionEvent e)
{
try
{
_textarea.setText("");
String ip = getCodeBase().getHost();
System.out.println( "ip:" + ip);
SnmpSession session = new SnmpSession(ip, 161, "public", "public", 1);
session.snmpGetSubtree(_subtreeOid.getText().trim(), this);
}
catch(Exception ex)
{
System.out.println(ex);
ex.printStackTrace();
}
}
}