Folks-

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

A very smart man once told me:
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.