MAC - Adresse auslesen
-
Hey Leute!
Und zwar würd ich gern die MAC - Adressen meiner Netzwerkkarten auslesen.
Hab dazu auch ein nützliches Programm mittels SNMP ausprobiert, doch leider kann ich mich mit dem Quellcode nicht anfreunden.
Vielleicht kann mir jemand weiterhelfen mit einem guten Tutorial oder mit einem einfach verständlichen Quellcode.
Danke!
-
#include <rpc.h>
#include <iostream>#ifdef _MSC_VER
using namespace std;
#endifint main()
{
cout << "MAC address is: ";// Ask RPC to create a UUID for us. If this machine has an Ethernet
// adapter, the last six bytes of the UUID (bytes 2-7 inclusive in
// the Data4 element) should be the MAC address of the local
// Ethernet adapter.
UUID uuid;
UuidCreate(&uuid);
// Spit the address out
for (int i = 2; i < 8; ++i) {
cout << hex;
cout.fill('0');
cout.width(2);
cout << int (uuid.Data4[i]);
if (i < 7) {
cout << ":";
}
}
cout << endl;return 0;
}
-
oder[url] http://tangentsoft.net/wskfaq/examples/ [/url]
-
Danke für die schnelle Antwort!
Doch mit dieser Methode bekomm ich leider nur eine MAC - Adresse.
Hab aber mehrere Netzwerkkarten und benötige von deswegen auch alle MAC - Adressen.
-
typedef struct _ASTAT { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff[30]; } ASTAT; int GetMacAddresses(TStrings* pslStrings) { int ilRetVal = 0; // Rückgabewert NCB stNetCtrlBlock; // Network Control Block - Instanz LPVOID pASTAT; // Zeiger auf die ASTAT-Struktur ASTAT stAdapterStatus; // AdapterStatus-Struktur LANA_ENUM stLanEnum; // Struktur für die Enumerierung der // Netzwerkkarten if(pslStrings != NULL) pslStrings->Clear(); memset(&stNetCtrlBlock, 0, sizeof(stNetCtrlBlock)); stNetCtrlBlock.ncb_command = NCBENUM; stNetCtrlBlock.ncb_buffer = (UCHAR *)&stLanEnum; stNetCtrlBlock.ncb_length = sizeof(stLanEnum); Netbios(&stNetCtrlBlock); ilRetVal = stLanEnum.length; if(pslStrings != NULL) { for(int ilAdapter=0; ilAdapter < ilRetVal; ilAdapter++) { stNetCtrlBlock.ncb_command = NCBRESET; Netbios(&stNetCtrlBlock); strcpy(stNetCtrlBlock.ncb_callname,"* "); stNetCtrlBlock.ncb_command = NCBASTAT; stNetCtrlBlock.ncb_lana_num = ilAdapter; stNetCtrlBlock.ncb_length = sizeof(stAdapterStatus); pASTAT=HeapAlloc(GetProcessHeap(),HEAP_GENERATE_EXCEPTIONS| HEAP_ZERO_MEMORY, stNetCtrlBlock.ncb_length); if(pASTAT != NULL) { stNetCtrlBlock.ncb_buffer=(UCHAR *)pASTAT; Netbios(&stNetCtrlBlock); CopyMemory(&stAdapterStatus,stNetCtrlBlock.ncb_buffer, sizeof(stAdapterStatus)); AnsiString slMacAddress; for(int i =0; i < 6; i++) { slMacAddress += IntToHex(stAdapterStatus.adapt.adapter_address[i],2); if(i<5) slMacAddress+="-"; } HeapFree(GetProcessHeap(),0,pASTAT); pslStrings->Add(slMacAddress); } else ilRetVal = 0; } } return ilRetVal; }
wenn das nicht hilft.... dann weiss ich auch nicht weiter