[SNMP4J] handling IP address formats
crichmond at referentia.com
Fri Jan 20 09:33:16 CET 2012
I am performing polling and one particular field for EIGRP neighbors in
cisco routers (.18.104.22.168.22.214.171.124.4126.96.36.199.1.3) returns ip addresses in
a hex string format delimited by ":"...such as c0:A8:01:23. This was
what I always got for devices I tested and I handled it like this in my
code using the SNMP4j classes :
/// neighborAddressStat.getValue().toString() = "c0:A8:01:23"
OctetString os =
org.snmp4j.smi.Address snmp4jIpAddress = new
neighborAddress = snmp4jIpAddress.toString();
where neighborAddress gives me a string "192.168.1.34"
Worked fine until some devices are now returning a string like
"192.168.1.34" instead of the hex string, which of course breaks this code.
There doesn't seem to be a comprehensive method or API in SNMP4j for
handling both situtions. In other words, org.snmp4j.smi.Address can
be constructed from a "192.168.1.34" string or a byte array. Octet
string breaks on "192.168.1.34" but can provide a byte array from a
It seems as though I am possibly missing the ideal way to handle this
within the Snmp4j library.
More information about the SNMP4J