![]() |
Introduction |
SNMP is still evolving. For a better understanding of the history of this framework, you should consider reading RFC 2570 (Introduction to SNMPV3).
SCK only deals with SMIV1 and SNMPV1.
SCK is the Snmp Construction Kit, a framework designed to allow anyone to build network management applications.
SCK is available under the GNU GPL.
import java.net.*;
import java.io.*;
import sck.*;
public class TrapReceiver{
private final static int trapPort = 162;
public static void main(String[] argv){
try {
DatagramSocket sock = new DatagramSocket(trapPort);
while (true){
byte[] b = new byte[1024];
DatagramPacket p = new DatagramPacket(b,b.length);
sock.receive(p); // block
ByteArrayInputStream ber = new ByteArrayInputStream(b,1,p.getLength()-1); // without tag, like all smi object !
Message m = new Message(ber);
System.out.println("Trap received at : " + new java.util.Date());
StringBuffer buf = new StringBuffer();
m.println("",buf);
System.out.println(buf);
}
}
catch (Exception e){
System.err.println(e);
System.exit(1);
}
}
}
To make tests, you can used an snmp agent on the Internet (ex: acscare.compu-shack.com) or install SNMP on your computer,
so you will be able to send requests to your favorite snmp agent (host 127.0.0.1).
You can now go to the Repository to see more examples or browse documentation: look at the SCK api doc and don't forget the class diagram.