News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

mac address

Started by george999, January 09, 2008, 10:20:37 PM

Previous topic - Next topic

george999

I am trying to get mac address.I call UuidCreateSequential and i readed that mac adress it's from byte 2 to 7,but on my computer it's from 11 to 16.
What is wrong?

GregL

#1
george999,

I don't know, but here is an example that works.


; MAC Address
.586
.MODEL FLAT, STDCALL
OPTION CASEMAP:NONE

INCLUDE     windows.inc

INCLUDE     user32.inc
INCLUDE     kernel32.inc
INCLUDE     IpHlpApi.inc

INCLUDELIB  user32.lib
INCLUDELIB  kernel32.lib
INCLUDELIB  IpHlpApi.lib

;------------------------------------------
; IP_ADAPTER_INFO STRUCT from Iptypes.h
;------------------------------------------
MAX_ADAPTER_NAME_LENGTH         EQU     256
MAX_ADAPTER_DESCRIPTION_LENGTH  EQU     128
MAX_ADAPTER_ADDRESS_LENGTH      EQU       8

PIP_ADAPTER_INFO EQU PTR IP_ADAPTER_INFO
PIP_ADDR_STRING  EQU PTR IP_ADDR_STRING

IP_ADDRESS_STRING STRUCT
    String BYTE (4 * 4) dup(0)
IP_ADDRESS_STRING ENDS   

IP_MASK_STRING STRUCT
    String BYTE (4 * 4) dup(0)
IP_MASK_STRING ENDS   

IP_ADDR_STRING STRUCT
    Next      DWORD 0     ;PIP_ADDR_STRING
    IpAddress IP_ADDRESS_STRING <> 
    IpMask    IP_MASK_STRING <>
    Context   DWORD 0
IP_ADDR_STRING ENDS

IP_ADAPTER_INFO  STRUCT
    Next                DWORD           0       ;PIP_ADAPTER_INFO
    ComboIndex          DWORD           0
    AdapterName         BYTE            (MAX_ADAPTER_NAME_LENGTH + 4) dup(0)
    Description         BYTE            (MAX_ADAPTER_DESCRIPTION_LENGTH + 4) dup(0)
    AddressLength       DWORD           0
    Address             BYTE            (MAX_ADAPTER_ADDRESS_LENGTH) dup(0)
    Index               DWORD           0
    uType               DWORD           0
    DhcpEnabled         DWORD           0
    CurrentIpAddress    DWORD           0       ;PIP_ADDR_STRING
    IpAddressList       IP_ADDR_STRING  <>
    GatewayList         IP_ADDR_STRING  <>
    DhcpServer          IP_ADDR_STRING  <>
    HaveWins            SDWORD          0
    PrimaryWinsServer   IP_ADDR_STRING  <>
    SecondaryWinsServer IP_ADDR_STRING  <>
    LeaseObtained       SDWORD          0
    LeaseExpires        SDWORD          0
IP_ADAPTER_INFO  ENDS   
;------------------------------------------

.DATA

    pAdapterInfo  DWORD 0   ;PIP_ADAPTER_INFO
    dwBufLen      DWORD 0
    dwByteVal0    DWORD 0
    dwByteVal1    DWORD 0
    dwByteVal2    DWORD 0
    dwByteVal3    DWORD 0
    dwByteVal4    DWORD 0
    dwByteVal5    DWORD 0
    szFormat      BYTE  "%02X-%02X-%02X-%02X-%02X-%02X", 0
    szBuffer      BYTE  18 dup (0)
    szTitle       BYTE  "MAC Address",0

.CODE

start:

    INVOKE  GetAdaptersInfo, NULL, ADDR dwBufLen          ; Get the buffer length required in dwBufLen

    INVOKE  GlobalAlloc, GMEM_FIXED, dwBufLen             ; Allocate the buffer
    mov     pAdapterInfo, eax                             ; Save the pointer to the buffer
   
    INVOKE  GetAdaptersInfo, pAdapterInfo, ADDR dwBufLen  ; Get the information into the buffer
   
    mov     edx, pAdapterInfo
    ASSUME  edx:PIP_ADAPTER_INFO

    movzx   eax, BYTE PTR [edx].Address[0]
    mov     dwByteVal0, eax
    movzx   eax, BYTE PTR [edx].Address[1]
    mov     dwByteVal1, eax
    movzx   eax, BYTE PTR [edx].Address[2]
    mov     dwByteVal2, eax
    movzx   eax, BYTE PTR [edx].Address[3]
    mov     dwByteVal3, eax
    movzx   eax, BYTE PTR [edx].Address[4]
    mov     dwByteVal4, eax
    movzx   eax, BYTE PTR [edx].Address[5]
    mov     dwByteVal5, eax
   
    ASSUME  edx:NOTHING
       
    INVOKE  wsprintf, ADDR szBuffer, ADDR szFormat, dwByteVal0, dwByteVal1, dwByteVal2, dwByteVal3, dwByteVal4, dwByteVal5
   
    INVOKE  GlobalFree, pAdapterInfo

    INVOKE  MessageBox, 0, ADDR szBuffer, ADDR szTitle, MB_OK

    INVOKE  ExitProcess, 0

END start


Vortex

Thanks Greg, nice example :U

GregL

Vortex,

Thanks, I just noticed dwByteVal6 is never used.