Hi Enrique, On Sat, 30 Aug 2008 14:55:47 +0200 "Enrique J. Garcia Diaz" wrote: > I am implementing a program that recover information of a snmp agent. > To get that, I am using SNMP4J. I have some problems when I want to > recover a table. Now, the problem is the values that are String I > only get this values in hexadecimal format. [...] > ifIndex = 0 > ifDescr = > 4d:53:20:54:43:50:20:4c:6f:6f:70:62:61:63:6b:20:69:6e:74:65:72:66:61:63:65:00 > (rather than MS TCP Loopback interface)
the problem is that snmp4j doesn't have sufficient type information to know how this variable should be formatted in to toString method. snmp4j only knows that ifDescr is an octet string, so it just makes a guess in the toString method: if all bytes are printable ASCII characters, then it's displayed as an ASCII string, otherwise it's displayed as a hex string. To further illustrate the problem, have a look at the ifPhysAddress which essentially is also just an octet string, but displaying that one as a hex string makes much more sense. In your specific case, the problem is that the Windows SNMP returns the ifDescr with a trailing '\0' character. So what you could do is to just get the byte array (OctetString.getValue()), remove any non-printable characters and then convert that to a String. If you are looking for a more general solution, you could use a MIB parser to get better type information from the MIB definitions, i.e. ifDescr is defined as a DisplayString and ifPhysAddress is defined as a PhysAddress. And if you are working with SNMPv2 MIB definitions, you will even get a DISPLAY-HINT so you can format the variables exactly as intended. Christof -- Emnico Services Ltd - http://www.emnico.com Dauntsey House, Stonehill Green, Westlea, Swindon SN5 7HB Company No. 06390113 This message is confidential and may contain privileged information. If you are not the addressee indicated in this message (or responsible for delivery of the message to them), you may not copy or deliver this message to anyone or take any action in reliance on it. If you have received this e-mail in error, please delete it and notify the sender as soon as possible. The Emnico group of companies do not accept any liability for any harm that may be caused to the recipient's system or data by this message. Please carry out virus and other such checks as you consider appropriate. _______________________________________________ SNMP4J mailing list SNMP4J@agentpp.org http://lists.agentpp.org/mailman/listinfo/snmp4j