Réponse: C'est possible ! Google est ton ami (et le miens aussi)
Je cite :
-------------------------------------------------------- De :Alex Vinokur (alexvn@bigfoot.com) Objet :Getting MAC Address (NetBIOS Method) within C/C++-program in Windows2000 This is the only article in this thread View: Original Format Groupes de discussion :alt.os.windows2000, comp.os.ms-windows.apps.winsock.misc, comp.os.ms-windows.misc, comp.os.ms-windows.programmer.misc, comp.os.ms-windows.programmer.tools.winsock, microsoft.public.win2000.general Date :2002-09-04 10:45:20 PST
=============================== Windows 2000 Professional ------------------- CYGWIN_NT-5 gcc/g++ version 2.95.3-5 (cygwin special) ------------------- MINGW-1.1 gcc/g++ version 2.95.3-6 (mingw special) ===============================
Here is a program getmac-netbios.cpp "How to Get the Ethernet MAC Address, NetBIOS Method" from http://tangentsoft.net/wskfaq/examples/getmac-netbios.html P.S. The only line has been added : cout << "MY INFO : AdapterList.length = " << static_cast<int>(AdapterList.length) << endl;
We can see that AdapterList.length == 0. So, we can't get MAC address.
Is something wrong ?
P.S.S. The program was running while I was working offline. Is it essential for this program ?
========= C++ Code : BEGIN ========= // File x2.cpp
#include <windows.h> #include <stdlib.h> #include <stdio.h> #include <iostream> #include <strstream> #include <string>
using namespace std;
bool GetAdapterInfo(int nAdapterNum, string & sMAC) { // Reset the LAN adapter so that we can begin querying it NCB Ncb; memset(&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBRESET; Ncb.ncb_lana_num = nAdapterNum; if (Netbios(&Ncb) != NRC_GOODRET) { char acTemp[80]; ostrstream outs(acTemp, sizeof(acTemp)); outs << "error " << Ncb.ncb_retcode << " on reset" << ends; sMAC = acTemp; return false; }
// Prepare to get the adapter status block memset(&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBASTAT; Ncb.ncb_lana_num = nAdapterNum; strcpy((char *) Ncb.ncb_callname, "*"); struct ASTAT { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff[30]; } Adapter; memset(&Adapter, 0, sizeof(Adapter)); Ncb.ncb_buffer = (unsigned char *)&Adapter; Ncb.ncb_length = sizeof(Adapter);
// Get the adapter's info and, if this works, return it in standard, // colon-delimited form. if (Netbios(&Ncb) == 0) { char acMAC[18]; sprintf(acMAC, "%02X:%02X:%02X:%02X:%02X:%02X", int (Adapter.adapt.adapter_address[0]), int (Adapter.adapt.adapter_address[1]), int (Adapter.adapt.adapter_address[2]), int (Adapter.adapt.adapter_address[3]), int (Adapter.adapt.adapter_address[4]), int (Adapter.adapt.adapter_address[5])); sMAC = acMAC; return true; } else { char acTemp[80]; ostrstream outs(acTemp, sizeof(acTemp)); outs << "error " << Ncb.ncb_retcode << " on ASTAT" << ends; sMAC = acTemp; return false; } }
int main() { // Get adapter list LANA_ENUM AdapterList; NCB Ncb; memset(&Ncb, 0, sizeof(NCB)); Ncb.ncb_command = NCBENUM; Ncb.ncb_buffer = (unsigned char *)&AdapterList; Ncb.ncb_length = sizeof(AdapterList); Netbios(&Ncb);
// Get all of the local ethernet addresses string sMAC; cout << "MY INFO : AdapterList.length = " << static_cast<int>(AdapterList.length) << endl; for (int i = 0; i < AdapterList.length; ++i) { if (GetAdapterInfo(AdapterList.lana[i], sMAC)) { cout << "Adapter " << int (AdapterList.lana[i]) << "'s MAC is " << sMAC << endl; } else { cerr << "Failed to get MAC address! Do you" << endl; cerr << "have the NetBIOS protocol installed?" << endl; break; } } return 0; }
------------------------------------------------------
J'ai testé ce prog et il fonctionne. Une chose: penser à la librairie netapi32.lib dans les options de ton linker.
Cordialement. ADPro22.
------------------------------- Réponse au message : -------------------------------
Vegeta :-)
salut a tous, je vourdai savoir comment faire en programmation la lecture de l'adresse physique de la carte reseau, lorsqu'on tape "ipconfig / all " sous dos, le resultat a coté de : adresse physique ecrit en hexadecimal
! et surtout si il ya 2 carte comment faire pour lire uniquement celle qu'on veut !
( si vous avez deja un programme qu'il le fait et qui ecrit le resultat dans un fichier c impeccable )
|