[SNMP4J] Sending SNMP traps with a different source IP Address

jaikar gupta gupta.jaikar at gmail.com
Wed Oct 27 03:55:18 CEST 2010


Dear Friends,

currently I can send traps, but the source IP Address is always my
computer's IP Address, I wonder if it is possible to send a trap
from my computer with a different IP Address.

I have tried setAgentAddress(IpAddress) method but no luck.

below is my method


public void sendSnmpV1Trap()
  {
    try
    {
      //Create Transport Mapping
      TransportMapping transport = new DefaultUdpTransportMapping();
      transport.listen();

      //Create Target
      CommunityTarget comtarget = new CommunityTarget();
      comtarget.setCommunity(new OctetString(community));
      comtarget.setVersion(SnmpConstants.version1);
      comtarget.setAddress(new UdpAddress("192.168.50.100"+ "/" + "162"));
      comtarget.setRetries(2);
      comtarget.setTimeout(5000);

      //Create PDU for V1
      PDUv1 pdu = new PDUv1();
      pdu.setType(PDU.V1TRAP);
      pdu.setEnterprise(new OID(trapOid));
      pdu.setGenericTrap(PDUv1.ENTERPRISE_SPECIFIC);
      pdu.setSpecificTrap(1);
      pdu.setAgentAddress(new IpAddress("192.168.50.123"));

      //Send the PDU
      Snmp snmp = new Snmp(transport);
      System.out.println("Sending V1 Trap to " + ipAddress + " on Port " +
port);
      snmp.send(pdu, comtarget);
      snmp.close();
    }
    catch (Exception e)
    {
      System.err.println("Error in Sending V1 Trap to " + ipAddress + " on
Port " + port);
      System.err.println("Exception Message = " + e.getMessage());
    }
  }


Thanks & Regards,

keepFaith
Jaikar Gupta



More information about the SNMP4J mailing list