Thanks for your interest. Thanks for any help you could provide.
For now I have the code in 2 different modules.
I am not able to correlate the adapter MAC address with the IP address.
'======================================================
'Module below is used to return a collection of Adapter MAC Addresses:
'=======================================================
Option Explicit
Private Const NCBASTAT As Long = &H33
Private Const NCBNAMSZ As Long = 16
Private Const HEAP_ZERO_MEMORY As Long = &H8
Private Const HEAP_GENERATE_EXCEPTIONS As Long = &H4
Private Const NCBRESET As Long = &H32
Private Const NCBENUM = &H37
Private Const MAX_LANA = 254
Private Type NET_CONTROL_BLOCK '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(9) As Byte ' Reserved, must be 0
ncb_event As Long
End Type
Private Type ADAPTER_STATUS
adapter_address(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
Private Type LANA_ENUM
Length As Integer
lana(MAX_LANA) As Integer
End Type
Private Declare Function Netbios Lib "netapi32.dll" (pncb As
NET_CONTROL_BLOCK) As Byte
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest
As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
Private Declare Function GetProcessHeap Lib "kernel32" () As Long
Private Declare Function HeapAlloc Lib "kernel32" (ByVal hHeap As Long,
ByVal dwFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function HeapFree Lib "kernel32" (ByVal hHeap As Long, ByVal
dwFlags As Long, lpMem As Any) As Long
Sub GetAdapterMacAddress(colAdapterMacAddress As Collection)
Dim colPhysicalAddress As New Collection
Dim PhysicalAddress$, tmp$
Dim pAstat&
Dim Ncb As NET_CONTROL_BLOCK
Dim Ast As ASTAT
Dim LEnum As LANA_ENUM
Dim pLEnum As Long
Dim i%, ByteNum%
Dim InList As Boolean
Dim NumDialups%
NumDialups = 0
Ncb.ncb_length = Len(LEnum)
pLEnum = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or
HEAP_ZERO_MEMORY, Ncb.ncb_length)
If pLEnum = 0 Then
MsgBox "memory allocation failed!", vbCritical
Exit Sub
End If
Ncb.ncb_buffer = pLEnum
Ncb.ncb_command = NCBENUM
Call Netbios(Ncb)
CopyMemory LEnum, Ncb.ncb_buffer, Len(LEnum)
HeapFree GetProcessHeap(), 0, pLEnum
For i = 0 To LEnum.Length - 1
If LEnum.lana(i) < 256 Then
Ncb.ncb_lana_num = LEnum.lana(i)
Ncb.ncb_command = NCBRESET
Call Netbios(Ncb)
HeapFree GetProcessHeap(), 0, pAstat 'bsm
Ncb.ncb_callname = "* "
Ncb.ncb_command = NCBASTAT
Ncb.ncb_lana_num = LEnum.lana(i)
Ncb.ncb_length = Len(Ast)
pAstat = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS Or
HEAP_ZERO_MEMORY, Ncb.ncb_length)
If pAstat = 0 Then
MsgBox "memory allocation failed!", vbCritical
Exit Sub
End If
Ncb.ncb_buffer = pAstat
Call Netbios(Ncb)
CopyMemory Ast, Ncb.ncb_buffer, Len(Ast)
PhysicalAddress$ = ""
For ByteNum = 0 To 5
If Len(PhysicalAddress$) > 0 Then PhysicalAddress$ =
PhysicalAddress$ & ":"
PhysicalAddress$ = PhysicalAddress$ & Right$("00" &
Hex$(Ast.Adapt.adapter_address(ByteNum)), 2)
Next
If PhysicalAddress$ = "44:45:53:54:00:00" Then
NumDialups = NumDialups + 1
PhysicalAddress$ = "dialup" & Trim$(NumDialups)
End If
On Error GoTo AlreadyInList
colPhysicalAddress.Add PhysicalAddress$, PhysicalAddress$
On Error GoTo 0
HeapFree GetProcessHeap(), 0, pAstat
End If
Next i
Set colAdapterMacAddress = colPhysicalAddress
Set colPhysicalAddress = Nothing
Exit Sub
AlreadyInList:
InList = True
Resume Next
End Sub
'=====================================================
'Module below is used to return a collection of Active Adapter Ip Addresses
'=====================================================
Option Explicit
Private Const WS_VERSION_REQD = &H101
Private Const WS_VERSION_MAJOR = WS_VERSION_REQD \ &H100 And &HFF&
Private Const WS_VERSION_MINOR = WS_VERSION_REQD And &HFF&
Private Const MIN_SOCKETS_REQD = 1
Private Const SOCKET_ERROR = -1
Private Const WSADescription_Len = 256
Private Const WSASYS_Status_Len = 128
Private Type hostent
hName As Long
hAliases As Long
hAddrType As Integer
hLength As Integer
haddrlist As Long
End Type
Private Type WSADATA
wVersion As Integer
wHighVersion As Integer
szDescription(0 To WSADescription_Len) As Byte
szSystemStatus(0 To WSASYS_Status_Len) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpszVendorInfo As Long
End Type
Private Declare Function WSAGetLastError Lib "WSOCK32.DLL" () As Long
Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal
wVersionRequired As Integer, lpWSADATA As WSADATA) As Long
Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long
Private Declare Function gethostname Lib "WSOCK32.DLL" (ByVal HostName$,
ByVal HostLen As Long) As Long
Private Declare Function gethostbyname Lib "WSOCK32.DLL" (ByVal HostName$)
As Long
Private Declare Sub RtlMoveMemory Lib "kernel32" (hpvDest As Any, ByVal
hpvSource&, ByVal cbCopy&)
Function hibyte(ByVal wParam As Integer)
hibyte = wParam \ &H100 And &HFF&
End Function
Function lobyte(ByVal wParam As Integer)
lobyte = wParam And &HFF&
End Function
Sub SocketsInitialize()
Dim WSAD As WSADATA
Dim iReturn As Integer
Dim sLowByte As String, sHighByte As String, sMsg As String
iReturn = WSAStartup(WS_VERSION_REQD, WSAD)
If iReturn <> 0 Then
MsgBox "Winsock.dll is not responding."
End
End If
If lobyte(WSAD.wVersion) < WS_VERSION_MAJOR Or (lobyte(WSAD.wVersion) =
WS_VERSION_MAJOR And hibyte(WSAD.wVersion) < WS_VERSION_MINOR) Then
sHighByte = Trim$(Str$(hibyte(WSAD.wVersion)))
sLowByte = Trim$(Str$(lobyte(WSAD.wVersion)))
sMsg = "Windows Sockets version " & sLowByte & "." & sHighByte
sMsg = sMsg & " is not supported by winsock.dll "
MsgBox sMsg
End
End If
'iMaxSockets is not used in winsock 2. So the following check is only
'necessary for winsock 1. If winsock 2 is requested,
'the following check can be skipped.
If WSAD.iMaxSockets < MIN_SOCKETS_REQD Then
sMsg = "This application requires a minimum of "
sMsg = sMsg & Trim$(Str$(MIN_SOCKETS_REQD)) & " supported sockets."
MsgBox sMsg
End
End If
End Sub
Sub SocketsCleanup()
Dim lReturn As Long
lReturn = WSACleanup()
If lReturn <> 0 Then
MsgBox "Socket error " & Trim$(Str$(lReturn)) & " occurred in Cleanup
"
End
End If
End Sub
Sub GetIpAdresses(ReturnHostname$, colHostIpAddresses As Collection)
Dim HostName As String * 256
Dim hostent_addr As Long
Dim host As hostent
Dim hostip_addr As Long
Dim temp_ip_address() As Byte
Dim i As Integer, NullPos As Integer
Dim ip_address As String
ReturnHostname$ = ""
Set colHostIpAddresses = Nothing
Set colHostIpAddresses = New Collection
SocketsInitialize
If gethostname(HostName, 256) = SOCKET_ERROR Then
MsgBox "Windows Sockets error " & Str(WSAGetLastError())
Exit Sub
Else
HostName$ = Trim$(HostName)
End If
hostent_addr = gethostbyname(HostName$)
If hostent_addr = 0 Then
MsgBox "Winsock.dll is not responding."
Exit Sub
End If
RtlMoveMemory host, hostent_addr, LenB(host)
RtlMoveMemory hostip_addr, host.haddrlist, 4
'get all active IP addresses
Do
ReDim temp_ip_address(1 To host.hLength)
RtlMoveMemory temp_ip_address(1), hostip_addr, host.hLength
For i = 1 To host.hLength
ip_address = ip_address & temp_ip_address(i) & "."
Next
ip_address = Trim$(Mid$(ip_address, 1, Len(ip_address) - 1))
colHostIpAddresses.Add ip_address, ip_address
ip_address = ""
host.haddrlist = host.haddrlist + LenB(host.haddrlist)
RtlMoveMemory hostip_addr, host.haddrlist, 4
Loop While (hostip_addr <> 0)
SocketsCleanup
'remove nulls from hostname
NullPos = InStr(HostName$, Chr$(0))
If NullPos > 1 Then HostName$ = Left$(HostName$, NullPos - 1)
ReturnHostname$ = Trim$(HostName$)
End Sub
===============================================
An alternative way of getting the MAC addresses involves the declaration:
Private Declare Function GetAdaptersInfo Lib "IPHlpApi" (IpAdapterInfo As
Any, pOutBufLen As Long) As Long
But this does not help me correlate the MAC and IP addresses.
...