This project has moved. For the latest updates, please go here.

Trouble getting MAC addresses

Topics: feature request (I want ...), usage (how to ...)
Jul 21, 2008 at 8:59 PM
Hi,

I'm having a hard time getting MAC addresses from a router. 

I'm using similar code to TestGet.cs:

        Manager manager = new Manager();
        try
        {
            Variable test = new Variable(new ObjectIdentifier(new uint[] { 1, 3, 6, 1, 2, 1, 4, 22, 1, 2, 10, 192, 168, 1, 10 }));
            Variable variable = manager.Get(VersionCode.V2, IPAddress.Parse("192.168.0.10"), "public", test);
            Console.WriteLine(variable.Data);
        }...


This is supposed to print "0:90:4b:e5:ad:85" but instead it prints "\0?K???". I've tried getting the same OID with Net-SNMP and it returns the correct value.

Any ideas?


Thanks,
-Trev

Coordinator
Jul 22, 2008 at 5:23 AM
Hi, it is possible because #SNMP treats the physical address as normal strings. It can be fixed. I am going to reproduce this on my dev machine to see if there is an easy way to extract physical address in a meaning format. Once I have done, I'll post an update here.
Coordinator
Aug 6, 2008 at 8:04 AM
Hi, .NET Framework has a specific class for MAC addresses called PhysicalAddress. So a new method is added in OctetString.cs in Change Set 14893. Now you can get a PhysicalAddress instance from it by calling ToPhysicalAddress.

However, this method may returns null if the OctetString instance is not a valid MAC address.

-Lex
Marked as answer by lextm on 10/6/2013 at 9:13 PM