ArticlesProjectsWeeklyCredentialsAbout

SNMP Get/Set/Trap in Java (1997)

Java code for sending SNMP GET and SET requests to a managed device and receiving asynchronous TRAP notifications — built on the JoeSNMP library with a working test harness.

networkingsnmpprotocolsinfrastructure

A real SNMP agent poller: GET a device's sysDescr, SET a community string, receive and decode a linkDown TRAP.

Source code
# SNMP Get/Set/Trap in Java (1997)

Code from the article [SNMP: How Network Management Actually Works](https://rishisharma.in/articles/snmp-protocol-internals).

Requires Java 1.1 and `joesnmp-0.3.0.jar` (or any SNMP4J-compatible library).

```sh
mkdir -p build
javac -cp lib/joesnmp-0.3.0.jar -d build src/*.java
# Poll a device
java -cp build:lib/joesnmp-0.3.0.jar com.motorola.nms.snmp.SnmpPoller 10.0.0.1 public
# Start trap listener on UDP 162
java -cp build:lib/joesnmp-0.3.0.jar com.motorola.nms.snmp.TrapListener 162
```

## Contents

- `src/com/motorola/nms/snmp/SnmpPoller.java` — synchronous SNMP GET/SET over UDP
- `src/com/motorola/nms/snmp/TrapListener.java` — asynchronous TRAP receiver bound to UDP 162
- `src/com/motorola/nms/snmp/OidConstants.java` — MIB-II OID constants (sysDescr, ifOperStatus, etc.)