From MSDN Q118623 HOWTO: Get the MAC Address for an Ethernet Adapter
Option Explicit
Private Const NCBNAMSZ = 16
Private Const MAX_LANA = 254
Private Const NCBRESET = &H32
Private Const NCBASTAT = &H33
Private Const NCBENUM = &H37
Private Type NCB
ncb_command As Byte
ncb_retcode As Byte
ncb_lsn As Byte
ncb_num As Byte
ncb_buffer As Long
ncb_length As Integer
ncb_callname As String * NCBNAMSZ
ncb_name As String * NCBNAMSZ
ncb_rto As Byte
ncb_sto As Byte
ncb_post As Long
ncb_lana_num As Byte
ncb_cmd_cplt As Byte
ncb_reserve(0 To 9) As Byte
ncb_event As Long
End Type
Private Type LANA_ENUM
Length As Integer
Lana(0 To MAX_LANA) As Integer
End Type
Private Const NRC_GOODRET = 0
Private Declare Function Netbios Lib "netapi32.dll" (pncb As NCB) As Byte
Private Type ADAPTER_STATUS
adapter_address(0 To 5) As Byte
rev_major As Byte
reserved0 As Byte
adapter_type As Byte
rev_minor As Byte
duration As Integer
frmr_recv As Integer
frmr_xmit As Integer
iframe_recv_err As Integer
xmit_aborts As Integer
xmit_success As Long
recv_success As Long
iframe_xmit_err As Integer
recv_buff_unavail As Integer
t1_timeouts As Integer
ti_timeouts As Integer
Reserved1 As Long
free_ncbs As Integer
max_cfg_ncbs As Integer
max_ncbs As Integer
xmit_buf_unavail As Integer
max_dgram_size As Integer
pending_sess As Integer
max_cfg_sess As Integer
max_sess As Integer
max_sess_pkt_size As Integer
name_count As Integer
End Type
Private Type NAME_BUFFER
name As String * NCBNAMSZ
name_num As Integer
name_flags As Integer
End Type
Private Type ASTAT
adapt As ADAPTER_STATUS
NameBuff(30) As NAME_BUFFER
End Type
Public Function LANA_List() As Variant
Dim NCB As NCB
Dim LANA_ENUM As LANA_ENUM
NCB.ncb_command = NCBENUM
NCB.ncb_buffer = VarPtr(LANA_ENUM)
NCB.ncb_length = Len(LANA_ENUM)
Dim Ret As Byte
Ret = Netbios(NCB)
If Ret <> NRC_GOODRET Then
Err.Raise 5, , "LANA_lst: Error from Netbios, return code = " & Ret
End If
If LANA_ENUM.Length > 0 Then
ReDim List(LANA_ENUM.Length - 1)
Dim Index As Long
For Index = 0 To LANA_ENUM.Length - 1
List(Index) = LANA_ENUM.Lana(Index)
Next Index
LANA_List = List
Else
LANA_List = Array()
End If
End Function
Public Function MacAddress(ByVal LANA_Number_IN As Long) As String
Dim NCB As NCB
Dim Ret As Byte
NCB.ncb_command = NCBRESET
Ret = Netbios(NCB)
If Ret <> NRC_GOODRET Then
Err.Raise 5, , "MacAddress: Error from Netbios, return code = " & Ret
End If
NCB.ncb_command = NCBASTAT
NCB.ncb_lana_num = LANA_Number_IN
NCB.ncb_callname = "*"
Debug.Assert NCB.ncb_callname = "* "
Dim ASTAT As ASTAT
NCB.ncb_length = Len(ASTAT)
Debug.Assert NCB.ncb_length = 680
NCB.ncb_buffer = VarPtr(ASTAT)
Ret = Netbios(NCB)
If Ret <> NRC_GOODRET Then
Err.Raise 5, , "MacAddress: Error from Netbios, return code = " & Ret
End If
MacAddress = Hex(ASTAT.adapt.adapter_address(0)) & " " & _
Hex(ASTAT.adapt.adapter_address(1)) _
& " " & Hex(ASTAT.adapt.adapter_address(2)) & " " _
& Hex(ASTAT.adapt.adapter_address(3)) _
& " " & Hex(ASTAT.adapt.adapter_address(4)) & " " _
& Hex(ASTAT.adapt.adapter_address(5))
End Function
Sub main()
Dim Lana As Variant
For Each Lana In LANA_List
Debug.Print Lana, MacAddress(Lana)
Next Lana
End Sub