How can I get the net adapter address?
-
How can I get the net adapter address? all the adapter is validate, but at some machine, I can get the adapter address, at some machine, I cann't (address is all Zero). The codes: ----------------------------------------------------------- #include typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff[30]; } ASTAT; void getNetID() { NCB ncb; UCHAR ch; memset(&ncb,0,sizeof(ncb)); ncb.ncb_command = NCBRESET; ch = Netbios(&ncb); // at some machine, ch = NRC_BRIDGE 0x23 // ncb_lana_num field invalid memset(ncb.ncb_callname,' ',sizeof(ncb.ncb_callname)); ncb.ncb_callname[0] = '*'; //lstrcpy(ncb.ncb_callname,"* "); ncb.ncb_command = NCBASTAT; ASTAT AST; ncb.ncb_lana_num = 0; ncb.ncb_length = sizeof(AST); long *pASTAT; pASTAT = (long *)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, ncb.ncb_length); if ( pASTAT == 0 ) { AfxMessageBox("memory allocation failed!"); return; } ncb.ncb_buffer = (unsigned char *)pASTAT; ch = Netbios(&ncb); CopyMemory(&AST, ncb.ncb_buffer, sizeof(ASTAT)); CString str( _T("") ); for(int i=0; i<6; i++) { if( i > 0 ) str += ' '; unsigned char c = (unsigned char)AST.adapt.adapter_address[i]; unsigned char m = (c>>4)&0xf; unsigned char n = c&0xf; str += (m>=10) ? (char)('A'+(m-10)) : (char)('0'+m); str += (n>=10) ? (char)('A'+(n-10)) : (char)('0'+n); } HeapFree(GetProcessHeap(), 0, pASTAT); AfxMessageBox( str ); } --------------------------------------- What's wrong? Thanks
-
How can I get the net adapter address? all the adapter is validate, but at some machine, I can get the adapter address, at some machine, I cann't (address is all Zero). The codes: ----------------------------------------------------------- #include typedef struct _ASTAT_ { ADAPTER_STATUS adapt; NAME_BUFFER NameBuff[30]; } ASTAT; void getNetID() { NCB ncb; UCHAR ch; memset(&ncb,0,sizeof(ncb)); ncb.ncb_command = NCBRESET; ch = Netbios(&ncb); // at some machine, ch = NRC_BRIDGE 0x23 // ncb_lana_num field invalid memset(ncb.ncb_callname,' ',sizeof(ncb.ncb_callname)); ncb.ncb_callname[0] = '*'; //lstrcpy(ncb.ncb_callname,"* "); ncb.ncb_command = NCBASTAT; ASTAT AST; ncb.ncb_lana_num = 0; ncb.ncb_length = sizeof(AST); long *pASTAT; pASTAT = (long *)HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY, ncb.ncb_length); if ( pASTAT == 0 ) { AfxMessageBox("memory allocation failed!"); return; } ncb.ncb_buffer = (unsigned char *)pASTAT; ch = Netbios(&ncb); CopyMemory(&AST, ncb.ncb_buffer, sizeof(ASTAT)); CString str( _T("") ); for(int i=0; i<6; i++) { if( i > 0 ) str += ' '; unsigned char c = (unsigned char)AST.adapt.adapter_address[i]; unsigned char m = (c>>4)&0xf; unsigned char n = c&0xf; str += (m>=10) ? (char)('A'+(m-10)) : (char)('0'+m); str += (n>=10) ? (char)('A'+(n-10)) : (char)('0'+n); } HeapFree(GetProcessHeap(), 0, pASTAT); AfxMessageBox( str ); } --------------------------------------- What's wrong? Thanks
Are you trying to get the MAC address of the Ethernet Adapter or the IP address?
-
Are you trying to get the MAC address of the Ethernet Adapter or the IP address?
Just want to get the adapter unique id! Thank you