Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ethernet card MAC address

0 views
Skip to first unread message

Seymen Ertas

unread,
Oct 28, 2003, 5:37:04 PM10/28/03
to
Hello,

Here is my problem, I can get a list of all the ethernet cards (mac
addresses) currently in the system however i have not found a way to easily
determine which card is for example a built in card and which one is a for
ex. PCMCIA card. My main problem is with laptops where there might be a
ethernet card built into the machine and the user might have plugged in
another ethernet card, at this point how do i make sure i look at the MAC
address of the built in ethernet card ? (I thought it would be the order
that they are enumarated by the system however this doesn't hold true for
all cases.

Also related to the above say you have a situation where the laptop has a
built in ethernet card but the docking station that this laptop goes into
also has another ethernet card how do you distinguish from these two in
order to find out the built in ethernet card ?

I use the Iphlpapi.dll with the following call: GetProcAddress(hLib,
"GetAdaptersInfo");
In order to get a list of ethernet cards and their information.

Thanks in advance for any suggestions.

Seymen

Rhett Gong

unread,
Oct 29, 2003, 2:37:38 AM10/29/03
to
Hi Seymen:
I think you can compare the IP_ADAPTER_INFO which you get from calling
GetAdaptersInfo. The IP_ADAPTER_INFO contains the info about AdapterName,
Description, hardware Address and type.You can compare them to distinguish
the card in some way. From the OS's point of view they're basically the
same: for example, a 3com NIC card might be a standalone PCI card, or might
be an on-board PCI chip. But it seems hard to distinguish which one is
built-in or not.

Best regards,

Rhett Gong [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.

Jeff Henkels

unread,
Oct 29, 2003, 8:27:17 AM10/29/03
to
Here's some code I wrote a couple weeks back -- it gets the MAC of the first
active NIC it finds (an active NIC being one that has an active connection
and an IP that's not localhost). It should work on Win98 and later.

#define IP_LOCALHOST 0x0100007F

LPBYTE GetActiveMAC()
{
DWORD i, dwSize;
PMIB_IPADDRTABLE pAddr = NULL;
MIB_IFROW iInfo;
PFIXED_INFO pFI = NULL;
BYTE byMAC[6] = { 0, 0, 0, 0, 0, 0 };

// Get all IP addresses held by this machine; if it's connected to a
network, there's at least one
// that's not localhost
dwSize = 0;
GetIpAddrTable(NULL, &dwSize, TRUE);
pAddr = (PMIB_IPADDRTABLE)new BYTE[dwSize];
if (!GetIpAddrTable(pAddr, &dwSize, TRUE))
{
for (i = 0; i < pAddr->dwNumEntries; ++i)
{
if (IP_LOCALHOST != pAddr->table[i].dwAddr)
{
// Not localhost, so get the interface
memset(&iInfo, 0, sizeof(MIB_IFROW));
iInfo.dwIndex = pAddr->table[i].dwIndex;
GetIfEntry(&iInfo);

if (MIB_IF_TYPE_ETHERNET == iInfo.dwType)
{
//iInfo.bPhysAddr contains the MAC address of this
interface
memcpy(&byMAC, iInfo.bPhysAddr, iInfo.dwPhysAddrLen);
delete[] (LPBYTE)pAddr;
return byMAC;
}
}
}
}
delete[] (LPBYTE)pAddr;
return NULL;
}

"Seymen Ertas" <sey...@nospam.com> wrote in message
news:ueGEEQa...@TK2MSFTNGP10.phx.gbl...

0 new messages