Domanda

I want create snmp client to some devices. However devices are not directly accessible from localhost . Want to use external ip to create the snmp client(session). How can I fullfill it using SNMP4j.

Below is the code snippet I use to create snmp client.

 public SNMPClient(String address) {
    super();
    this.address = address;
    try {
        start();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

private void start() throws IOException {

    TransportMapping transport = new DefaultUdpTransportMapping();

    // Create Target Address object
    this.target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setVersion(SnmpConstants.version2c);
    target.setAddress(new UdpAddress(address));
    target.setRetries(2);
    target.setTimeout(50000);
    snmp = new Snmp(transport);

    transport.listen();
}

I tried to give extrenal IP during transport creation like shown below

TransportMapping transport = new DefaultUdpTransportMapping(new UdpAddress("192.8.8.8"));

But does not seems to be working.

Please suggest how can I go ahead?

Thanks in advance, Brinal

È stato utile?

Soluzione

You're missing listening port definition in your code. This is how it should work

TransportMapping transport = new DefaultUdpTransportMapping(new UdpAddress("192.8.8.8/161"));
  • 161 port for listening to standard snmp agent query responses
  • 162 listening for snmp agent trap messages

But iam not sure if i fully understand your question. SNMP clients (managers) are used to query snmp agents running on network devices (such as routers, PCs, printers etc) and receive responses for these queries. Managers also listen for trap messages fired by snmp agents. Is your purpose to create snmp manager or agent?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top