To send a broadcast SNMP message to a target, simply

  1. use a broadcast address as target
  2. use SNMP v1, v2c, or v3 with noAuthNoPriv security level (broadcast with authentication does not work obviously)
  3. use the asynchronous response processing model of SNMP4J

For example:

.h5 Setup a Snmp instance and let it listen to responses

   TransportMapping transport = new DefaultUdpTransportMapping();
   Session snmp = new Snmp(transport);
   USM usm = new USM(SecurityProtocols.getInstance(),
                     new OctetString(MPv3.createLocalEngineID()), 0);
   SecurityModels.getInstance().addSecurityModel(usm);
   snmp.listen();

.h5 Create a broadcast target:

Address targetAddress = GenericAddress.parse("udp:255.255.255.255/161");

.h5 Create the PDU

PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,1})));
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,2})));
pdu.setType(PDU.GETNEXT);

.h5 Send the message asynchronously

boolean 
ResponseListener listener = new ResponseListener() {
  public void onResponse(ResponseEvent event) {
     System.out.println("Received response PDU is: "+event.getResponse());
     if (event.getResponse() == null) {
       listener.notify();
     }
   }
 };
 
 snmp.sendPDU(pdu, target, null, listener);
 try {
   listener.wait(target.getTimeout()*2);
 } catch (InterruptedException iex) {
     System.out.println("Request cancelled: "+iex.getMessage());
 }