[win32] mac adres ophalen zonder netbios

Pagina: 1
Acties:

  • xoror
  • Registratie: November 1999
  • Niet online
hallo,

ik gebruik de NdisRequest om het mac adres op te halen. Het nadeel hieraan is dat je netbios voor de betreffende NIC netbios aan moet hebben staan.

ipconfig /all bijvoorbeeld kan het ook blijkbaar zonder netbios doen. Iemand die weet hoe dit moet met win32 apicalls (zonder gebruik te maken van netbios)?
Daarbij kan ipconfig /all ook mac adres ophalen als de nic niet ge-connect is.
Not all machines have a real MAC address, only those with LAN cards. Given that fact, an NdisRequest() for OID_802_3_CURRENT_ADDRESS will give you the right answer, provided the NetBIOS protocol stack is installed on the PC. This used to be common on Win95 boxes, but with Win98 and NT installing TCP/IP as the default stack, it is becoming rarer.
NB: The OLE function CoCreateGUID() will try to create a unique GUID, the last 64 bits of which are usually the MAC address of a card on the PC. Do not rely on this 100% of the time, as the algorithm does other things when running on a PC without a network interface. And on NT5 it stops using the MAC address at all, for privacy reasons

Mitsubishi Warmtepomp Uitlezen / Besturen | Optimaliseren


Verwijderd

GetIfTable kan 'm ophoesten per nic. geen idee of die stiekum netbios gebruikt ofzo

  • xoror
  • Registratie: November 1999
  • Niet online
ik heb denk ik gevonden , dit moet werken zonder netbios.
eens even testen.

Method Three: Use GetAdaptersInfo
The cleanest way I could find to get all the MAC addresses located on a PC was to use the GetAdaptersInfo method. It includes almost as much information as IPCONFIG /ALL including your DHCP server, Gateway, IP address list, subnet mask and WINS servers. It also enumerates all the NICs on your PC and is supported in 95/98/Me/NT/2000/XP. Finally it also works if your NICs are not connected to valid networks (eg. wires are not even hooked up), but the NICs do have to be "enabled" in Windows.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
  IP_ADAPTER_INFO AdapterInfo[16];       // Allocate information 
                                         // for up to 16 NICs
  DWORD dwBufLen = sizeof(AdapterInfo);  // Save memory size of buffer

  DWORD dwStatus = GetAdaptersInfo(      // Call GetAdapterInfo
    AdapterInfo,                 // [out] buffer to receive data
    &dwBufLen);                  // [in] size of receive data buffer
  assert(dwStatus == ERROR_SUCCESS);  // Verify return value is 
                                      // valid, no buffer overflow

  PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo; // Contains pointer to
                                               // current adapter info
  do {
    PrintMACaddress(pAdapterInfo->Address); // Print MAC address
    pAdapterInfo = pAdapterInfo->Next;    // Progress through 
                                          // linked list
  }
  while(pAdapterInfo);                    // Terminate if last adapter
}


I probably should mention that statically allocating an array for up to 16 NICs is not the best way to do this. It is a quick and dirty solution that should show you essentially how to get and enumerate all the MAC addresses on your PC.

ik heb getest en het werkt. hij detect ook de 'offline' nics.

Mitsubishi Warmtepomp Uitlezen / Besturen | Optimaliseren