SNMP Code Example: Interpret a MAC or IP address value
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:
C#
SNMPObject obj = new SNMPObject();
obj.Oid = "1.3.6.1.2.1.2.2.1.6";
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") + " ";
}
var MACAddress : String;
var i : Integer;
var response : RawByteString;
begin
SNMPMgr1.ObjCount := 1;
SNMPMgr1.ObjId[0] := '1.3.6.1.2.1.2.2.1.6';
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 article please contact our support team at kb@nsoftware.com.