SNMP Code Example: Interpret a MAC or IP address value

By using the ValueB field of the Objects collection we can build a string representation of the MAC or IP address.

Date Entered: 06/09/2008    Last Updated: 03/31/2017

If a response from an agent is a MAC or IP address, you will need to use the ValueB field of the Objects collection instead of the Value field. For instance:


SNMPObject obj = new SNMPObject(); obj.Oid = ""; snmpmgr1.Objects.Add(obj); snmpmgr1.SendGetRequest(); string MACAddress = null; for (int i = 0; i < snmpmgr1.Objects[0].ValueB.Length; i++) { MACAddress += snmpmgr1.Objects[0].ValueB[i].ToString("X") + " "; }

Delphi var MACAddress : String; var i : Integer; var response : RawByteString; begin SNMPMgr1.ObjCount := 1; SNMPMgr1.ObjId[0] := ''; SNMPMgr1.SendGetRequest(); response := SNMPMgr1.ObjValueB[0]; for i:= 0 to Length(response) do begin MACAddress := MACAddress + ' ' + IntToHex(ord(response[i]),2); end; ShowMessage(MACAddress); end;

We appreciate your feedback.  If you have any questions, comments, or suggestions about this entry please contact our support team at