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