Prev: Win64 , InterlockedCompareExchange128 and early AMDs
Next: Retrieving the filesystem name of each partition not mounted
From: Jochen Kalmbach [MVP] on 11 Feb 2007 04:08 Hi Andrew! > Is there a SDK or Platform API call that will return the MAC address(es) in > a host? See: http://support.microsoft.com/kb/118623/en-us or http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_networkadapter.asp or CString GetMACAddress(int adapternumber) { int nAdapterCount = 0; ULONG ip; ULONG buflen; PIP_ADAPTER_INFO pAdInfo = NULL; PIP_ADAPTER_INFO pAdInfo_c = NULL; buflen = 0; GetAdaptersInfo(pAdInfo, &buflen); //since buflen=0, buffer is // too small. function returns required buffersize in buflen. pAdInfo = (struct _IP_ADAPTER_INFO *)new UCHAR[buflen+1]; pAdInfo_c = pAdInfo; if (GetAdaptersInfo(pAdInfo, &buflen) == ERROR_SUCCESS) { do { ip = inet_addr(pAdInfo->IpAddressList.IpAddress.String); if ((ip != 0)&&(ip != 0x7f000001)) { nAdapterCount++; if ((nAdapterCount == adapternumber)||(adapternumber == 0)) { if (pAdInfo->AddressLength != 0) { CString macstr; for (int i = 0; i < (int)pAdInfo->AddressLength; i++) { CString temp; temp.Format(_T(" %02X"), pAdInfo->Address[i]); macstr += temp; } delete pAdInfo; return macstr; } } } } while ((pAdInfo->Next != NULL)&&((pAdInfo = pAdInfo->Next) != pAdInfo)); } delete pAdInfo_c; return _T(""); } -- Greetings Jochen My blog about Win32 and .NET http://blog.kalmbachnet.de/
From: Anton Bassov on 11 Feb 2007 13:03 I would rather open a handle to the target adapter with CreateFile(), and then send OID_XXX_PERMANENT_ADDRESS request to it with IOCTL_NDIS_QUERY_GLOBAL_STATS ..... Names of all adapters TCPIP is bound to (i.e. the ones that can be passed to CreateFile() call) can be found under HKLM \\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters key in the registry. First I would send OID_GEN_SUPPORTED_LIST request in order to find all OIDs that adapter supports, and locate OID_XXX_PERMANENT_ADDRESS ( OID!= OID_GEN_SUPPORTED_LIST && OID&0xffffff== OID_GEN_SUPPORTED_LIST). At this point I would be able to send OID_XXX_PERMANENT_ADDRESS, and obtain the sought info.... Anton Bassov "Andrew Chalk" wrote: > Is there a SDK or Platform API call that will return the MAC address(es) in > a host? > > Many thanks. > > >
From: Arkady Frenkel on 12 Feb 2007 02:43 Obviously that should work even on Vista, but MSFT for years warning about near deprecation of IOCTL_NDIS_QUERY_GLOBAL_STATS for security reasons. OTOH that give option to check MAC on local host only ( in addition to GetIfTable()/GetIfEntry and GetAdaptersInfo )and that no what OP mean if I understood him correctly. In that case in addition to Netbios ( may not work if it disabled ) and SendARP() possible to use WMI's MACAddress property of Win32_NetworkAdapter interface . Arkady "Anton Bassov" <AntonBassov(a)discussions.microsoft.com> wrote in message news:634A9F45-589A-410B-A3B2-A0651F90A19E(a)microsoft.com... >I would rather open a handle to the target adapter with CreateFile(), and >then > send OID_XXX_PERMANENT_ADDRESS request to it with > IOCTL_NDIS_QUERY_GLOBAL_STATS ..... > > Names of all adapters TCPIP is bound to (i.e. the ones that can be passed > to > CreateFile() call) can be found under > HKLM \\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters > key in the registry. First I would send OID_GEN_SUPPORTED_LIST request in > order to find all OIDs that adapter supports, and locate > OID_XXX_PERMANENT_ADDRESS > ( OID!= OID_GEN_SUPPORTED_LIST && OID&0xffffff== OID_GEN_SUPPORTED_LIST). > At this point I would be able to send OID_XXX_PERMANENT_ADDRESS, and > obtain > the sought info.... > > Anton Bassov > > "Andrew Chalk" wrote: > >> Is there a SDK or Platform API call that will return the MAC address(es) >> in >> a host? >> >> Many thanks. >> >> >>
From: Anton Bassov on 12 Feb 2007 03:11 Arkady, > Obviously that should work even on Vista, but MSFT for years warning about > near deprecation of IOCTL_NDIS_QUERY_GLOBAL_STATS for security reasons. Well, taking into consideration the fact that it is miniport driver and not TCPIP.SYS who handles this request (which is optional anyway), as well as the one that this IOCTL gets submitted to the standalone device that is not on any stack, there is not that much that they can do about it, apart from removing NdisMRegisterDevice(), i.e. dropping the support for standalone devices. I don't think they want to go that far.... > OTOH that give option to check MAC on local host only ( in addition to > GetIfTable()/GetIfEntry and GetAdaptersInfo )and that no what OP mean if I > understood him correctly. The way I understood it, the OP was asking about the local host. Maybe I just got it wrong..... Anton Bassov "Arkady Frenkel" wrote: > Obviously that should work even on Vista, but MSFT for years warning about > near deprecation of IOCTL_NDIS_QUERY_GLOBAL_STATS for security reasons. > OTOH that give option to check MAC on local host only ( in addition to > GetIfTable()/GetIfEntry and GetAdaptersInfo )and that no what OP mean if I > understood him correctly. > In that case in addition to Netbios ( may not work if it disabled ) and > SendARP() possible to use WMI's MACAddress property of Win32_NetworkAdapter > interface . > > Arkady > > "Anton Bassov" <AntonBassov(a)discussions.microsoft.com> wrote in message > news:634A9F45-589A-410B-A3B2-A0651F90A19E(a)microsoft.com... > >I would rather open a handle to the target adapter with CreateFile(), and > >then > > send OID_XXX_PERMANENT_ADDRESS request to it with > > IOCTL_NDIS_QUERY_GLOBAL_STATS ..... > > > > Names of all adapters TCPIP is bound to (i.e. the ones that can be passed > > to > > CreateFile() call) can be found under > > HKLM \\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters > > key in the registry. First I would send OID_GEN_SUPPORTED_LIST request in > > order to find all OIDs that adapter supports, and locate > > OID_XXX_PERMANENT_ADDRESS > > ( OID!= OID_GEN_SUPPORTED_LIST && OID&0xffffff== OID_GEN_SUPPORTED_LIST). > > At this point I would be able to send OID_XXX_PERMANENT_ADDRESS, and > > obtain > > the sought info.... > > > > Anton Bassov > > > > "Andrew Chalk" wrote: > > > >> Is there a SDK or Platform API call that will return the MAC address(es) > >> in > >> a host? > >> > >> Many thanks. > >> > >> > >> > > >
From: Arkady Frenkel on 12 Feb 2007 10:24
Anton! "Anton Bassov" <AntonBassov(a)discussions.microsoft.com> wrote in message news:79D44CFC-A70F-4349-9F8C-F5A916380E39(a)microsoft.com... > Arkady, > >> Obviously that should work even on Vista, but MSFT for years warning >> about >> near deprecation of IOCTL_NDIS_QUERY_GLOBAL_STATS for security >> reasons. > > Well, taking into consideration the fact that it is miniport driver and > not > TCPIP.SYS who handles this request (which is optional anyway), as well as > the > one that this IOCTL gets submitted to the standalone device that is not on > any stack, there is not that much that they can do about it, apart from > removing NdisMRegisterDevice(), i.e. dropping the support for standalone > devices. I don't think they want to go that far.... > I don't think that it's a problem for MSFT to decline that already in DeviceIoControl() in user mode or before extract/send OID in kernel mode Arkady >> OTOH that give option to check MAC on local host only ( in addition to >> GetIfTable()/GetIfEntry and GetAdaptersInfo )and that no what OP mean if >> I >> understood him correctly. > > The way I understood it, the OP was asking about the local host. Maybe I > just got it wrong..... > > Anton Bassov > > > "Arkady Frenkel" wrote: > >> Obviously that should work even on Vista, but MSFT for years warning >> about >> near deprecation of IOCTL_NDIS_QUERY_GLOBAL_STATS for security >> reasons. >> OTOH that give option to check MAC on local host only ( in addition to >> GetIfTable()/GetIfEntry and GetAdaptersInfo )and that no what OP mean if >> I >> understood him correctly. >> In that case in addition to Netbios ( may not work if it disabled ) and >> SendARP() possible to use WMI's MACAddress property of >> Win32_NetworkAdapter >> interface . >> >> Arkady >> >> "Anton Bassov" <AntonBassov(a)discussions.microsoft.com> wrote in message >> news:634A9F45-589A-410B-A3B2-A0651F90A19E(a)microsoft.com... >> >I would rather open a handle to the target adapter with CreateFile(), >> >and >> >then >> > send OID_XXX_PERMANENT_ADDRESS request to it with >> > IOCTL_NDIS_QUERY_GLOBAL_STATS ..... >> > >> > Names of all adapters TCPIP is bound to (i.e. the ones that can be >> > passed >> > to >> > CreateFile() call) can be found under >> > HKLM \\SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Adapters >> > key in the registry. First I would send OID_GEN_SUPPORTED_LIST request >> > in >> > order to find all OIDs that adapter supports, and locate >> > OID_XXX_PERMANENT_ADDRESS >> > ( OID!= OID_GEN_SUPPORTED_LIST && OID&0xffffff== >> > OID_GEN_SUPPORTED_LIST). >> > At this point I would be able to send OID_XXX_PERMANENT_ADDRESS, and >> > obtain >> > the sought info.... >> > >> > Anton Bassov >> > >> > "Andrew Chalk" wrote: >> > >> >> Is there a SDK or Platform API call that will return the MAC >> >> address(es) >> >> in >> >> a host? >> >> >> >> Many thanks. >> >> >> >> >> >> >> >> >> |