[Mono-dev] get mac address using system.management

Mike Edenfield kutulu at kutulu.org
Mon Apr 13 16:40:41 EDT 2009


On 4/13/2009 1:50 PM, tooty wrote:

> so, can anyone tell me what is the wright method of managementclass that
> will let me get the network adapter properties?

I don't believe any of the System.Management namespace is currently 
implemented, for exactly the reason you specified: WMI is way too 
closely tied to Windows.

> or any other way i should use for linux system?
> thnx in advance.

The typical ways on a Unix system to get the hardware address:

* Run ifconfig and parse the output (e.g. via Process())

* On Linux, at least, you can read from sysfs (assuming a new enough 
kernel):  /sys/class/net/<ifname>/address

* Open a socket, and send it an ioctl(SIOCGIFHWADDR), passing in a 
struct ifreq with the "ifr_name" field set to the interface name.  On 
return, the "ifr_hwaddr.sa_data" field contains the hardware address. 
You should be able to use the Socket::IOControl method to help here.

* Read the kernel source for how SIOCGIFHWADDR is implemented, then do 
that :)  Probably involving way more work with DllImport, Marshalling, 
and syscalls than you want to think about.






More information about the Mono-devel-list mailing list