SNMP4J

Extensible SNMPv3 open source stack for Java SE 8 or later

with MD5, SHA-1, SHA-2 and DES, 3DES, and AES security, as well as UDP, TCP, TLS, DTLS transport.

SNMP-Agent Development

Developing an SNMP agent is far more complex than implementing a SNMP manager. SNMP4J-Agent - the defacto standard for Java SNMP agent development - reduces that complexity to a minimum.
Use AgenPro code generator to create an agent from exisiting MIBs instantly and safe even more time and effort!

Download SNMP4J-Agent Tutorial

API Documentation

SNMP4J is open source and has a very good API documentation even down to the details. Don't miss it!

API Documentation

SNMP4J

Send SNMP commands, send and receive notifications/traps and informs. This is the base API for any SNMP application or agent.

More...

SNMP4J-Agent

Extend SNMP4J with agent (command responder) capabilities. Implement atomic SET operations with 2-phase commit, table, and GETBULK operations.

More...

SNMP4J-AgentX

Add AgentX master/subagent support to any SNMP4J-Agent and buffered table models to support large tables efficiently.

More...

SNMP4J-SMI-PRO

Use SMI MIB module specifications to use object name to identifier (OID) mapping and syntax conversions with all SNMP4J APIs at runtime.

More...

SNMP4J Sample Code - GETNEXT with SNMPv3 (SHA256+AES128)


/**
 * Brief flow description of using the new SNMP4J fluent interface: 
 * SnmpBuilder.udp()...build() => Snmp
 * SnmpBuilder.target(..) => TargetBuilder 
 *     TargetBuilder.user(..)...done()...build() => Target
 *     TargetBuilder.pdu()...build() => PDUrequest
 * SnmpCompletableFuture.send(Snmp, Target, PDUrequest) => SnmpCompletableFuture
 * SnmpCompletableFuture.get() => PDUresponse
 */

public class UsmGetNext {

    public void nextFluent(String address, String contextName, String securityName,
                           String authPassphrase, String privPassphrase, String... oids) throws IOException {
        SnmpBuilder snmpBuilder = new SnmpBuilder();
        Snmp snmp = snmpBuilder.udp().v3().usm().threads(2).build();
        snmp.listen();
        Address targetAddress = GenericAddress.parse(address);
        byte[] targetEngineID = snmp.discoverAuthoritativeEngineID(targetAddress, 1000);
        if (targetEngineID != null) {
            TargetBuilder<?> targetBuilder = snmpBuilder.target(targetAddress);
            Target<?> userTarget = targetBuilder
                    .user(securityName, targetEngineID)
                    .auth(TargetBuilder.AuthProtocol.hmac192sha256).authPassphrase(authPassphrase)
                    .priv(TargetBuilder.PrivProtocol.aes128).privPassphrase(privPassphrase)
                    .done()
                    .timeout(500).retries(1)
                    .build();

            PDU pdu = targetBuilder.pdu().type(PDU.GETNEXT).oids(oids).contextName(contextName).build();
            SnmpCompletableFuture snmpRequestFuture = SnmpCompletableFuture.send(snmp, userTarget, pdu);
            try {
                List<VariableBinding> vbs = snmpRequestFuture.get().getAll();

                System.out.println("Received: " + snmpRequestFuture.getResponseEvent().getResponse());
                System.out.println("Payload:  " + vbs);
            } catch (ExecutionException | InterruptedException ex) {
                if (ex.getCause() != null) {
                    System.err.println(ex.getCause().getMessage());
                } else {
                    System.err.println("Request failed: "+ex.getMessage());
                }
            }
        }
        else {
            System.err.println("Timeout on engine ID discovery for "+targetAddress+", GETNEXT not sent.");
        }
        snmp.close();
    }

    public static void main(String[] args) {
        if (args.length < 5) {
            System.out.println("Usage: UsmGetNext <address> <secName> <authPassphrase> <privPassphrase> <oid>...");
            System.out.println("where <address> is of the form 'udp:<hostname>/<port>'");
        }
        String targetAddress = args[0];
        String context = "";
        String securityName = args[1];
        String authPasssphrase = args[2].length() == 0 ? null : args[2];
        String privPasssphrase = args[3].length() == 0 ? null : args[3];
        String[] oids = new String[args.length - 4];
        System.arraycopy(args, 4, oids, 0, args.length - 4);
        UsmGetNext usmGetNext = new UsmGetNext();
        try {
            usmGetNext.nextFluent(targetAddress, context, securityName, authPasssphrase, privPasssphrase, oids);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
			  
Card image cap
Create custom MIBs with MIB Designer

Use MIB Designer to create, edit, and manage organizational MIB specifications. Ensure 100% standard compliance & interoperability.

More...
Card image cap
Code Generation with AgenPro

Generate SNMP4J agent and manager code with ready-to-use but modifiable templates that support round-trip engineering.

More...
Card image cap
Explore and test SNMP devices with MIB Explorer

Debug, test, explore, monitor, and configure SNMP agents intuitivly. MIB Explorer is built with SNMP4J and SNMP4J-SMI-PRO!

More...

OID vacmAccessContextMatch = new OID("1.3.6.1.6.3.16.1.4.1.4.7.118.51.103.114.111.117.112.0.3.1");
System.out.println("> "+vacmAccessContextMatch.toString())
With SNMP4J only:
> 1.3.6.1.6.3.16.1.4.1.4.7.118.51.103.114.111.117.112.0.3.1
With SNMP4J-SMI-PRO:
> vacmAccessContextMatch."v3group"."\".3.'noAuthNoPriv(1)'
Construct OIDs by using object names too:
assertEquals(new OID("vacmAccessContextMatch.\"v3group\".\"\".3.'noAuthNoPriv(1)'"), vacmAccessContextMatch);
assertEquals(new OID("vacmAccessContextMatch.7.118.51.103.114.111.117.112.\"\".3.'noAuthNoPriv(1)'"), vacmAccessContextMatch);
assertEquals(new OID("vacmAccessContextMatch.7.118.51.103.114.111.117.112.\"\".3.1"), vacmAccessContextMatch;
			
MIB Information @Runtime with SNMP4J-SMI-PRO

SNMP4J seamlessly uses SMI MIB data provided by the SNMP4J-SMI-PRO API and MIB compiler.

More...

Contact Us

AGENTPP
Maximilian-Kolbe-Str. 10
73257 Köngen, Germany
P: +49 7024 8688230

Forum

AGENTPP Forum

About Us

SNMP4J.org was founded 2003 to provide an open source SNMP API based on the experiences with SNMP++ and AGENT++ development by AGENTPP since 1998. The initial version of SNMP4J was released April, 2004. SNMP4J is the first Apache 2 Open Source licensed pure Java SNMP library supporting all IETF standard SNMP versions, transport mappings, and security protocols.

AGENTPP was founded 1998 by Frank Fock. AGENTPP provides commercial APIs, support, and SMNP development tools. These offerings are funding and ensuring the continuous free open source SNMP4J development.