I have a perl program that needs to get both the current, and permanent MAC addresses of the motherboard ethernet interfaces, when running under windows.
After doing some pretty extensive research into this, I believe this is possible by using communicating directly to the device drivers via NDIS using the following OIDs:
OID_802_3_PERMANENT_ADDRESS
OID_802_3_CURRENT_ADDRESS
see: http://msdn2.microsoft.com/en-us/library/bb314146.aspx
http://msdn2.microsoft.com/en-us/library/bb314406.aspx
The basic strategy is to use SetupDi to enumerate: hDeviceInfoSet = SetupDiGetClassDevs( &GUID_NDIS_LAN_CLASS, NULL, // Define no enumerator (global) NULL, // Define no (DIGCF_PRESENT | // Only Devices present DIGCF_PROFILE | // In Current Hardware Profile DIGCF_INTERFACEDEVICE) // Function class devices. ); Then SetupDiEnumDeviceInterfaces and finally SetupDiGetDeviceInterface +Detail on each interface. Gets kind of messy. You will finally get the information you need to make the call on IOCTL_NDIS_QUERY_GLOBAL_STATS to fetch the permanent address.
I am looking to get access to this information from perl. The closest thing that I've found to date is Win32::NetPacket, however it requires the winpcap Packet Driver API (Packet.dll), whose copyright is not compatible with my use, and there is a bug in WinPcap 3.1 that is fixed in a later version that this module doesn't work with (yet). Also, this is very much overkill for my purposes.
I wonder if there is an easier/better/existing way to do this?
I have no clue on how to figure out if an interface exists on the motherboard or not.
Any help is much appreciated (now that I'm at novice level, I can actually bestow XP points)!
Thanks
-Craig
Update: The solution I went with can be found in my code snippet WIN32: Permanent & Current MAC Addresses. Thanks to all for the great help! In reply to Getting MAC Address(s) on Windows PCs
by cmv
For:
Use:
& & < < > > [ [ ] ]