Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How can I get the net adapter address?

How can I get the net adapter address?

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wangyiming
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • W wangyiming

      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

      A Offline
      A Offline
      Albert Pascual
      wrote on last edited by
      #2

      Are you trying to get the MAC address of the Ethernet Adapter or the IP address?

      W 1 Reply Last reply
      0
      • A Albert Pascual

        Are you trying to get the MAC address of the Ethernet Adapter or the IP address?

        W Offline
        W Offline
        wangyiming
        wrote on last edited by
        #3

        Just want to get the adapter unique id! Thank you

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups