Public Declare Function GetAdaptersInfo Lib "IPHlpApi" (IpAdapterInfo As Any, pOutBufLen As Long) As Long
Public Const ERROR_BUFFER_OVERFLOW = 111
Public Type IP_ADDR_STRING
tLng_NextIPAddr As Long
tStr_ThisIpAddress As String * 16
tStr_ThisIpMask As String * 16
tStr_ThisContext As Long
End Type
Public Type IP_ADAPTER_INFO
tLng_NextApapter As Long
tLng_ComboIndex As Long
tStr_AdapterName As String * 260
tStr_Description As String * 132
tLng_AddressLength As Long
tByt_PhysicalAddress(7) As Byte
tLng_Index As Long
tLng_Type As Long
tLng_DhcpEnabled As Long
tLng_CurrentIpAddress As Long
tIPA_IpAddressList As IP_ADDR_STRING
tIPA_GatewayList As IP_ADDR_STRING
tIPA_DhcpServer As IP_ADDR_STRING
tBol_HaveWins As Boolean
tIPA_PrimaryWinsServer As IP_ADDR_STRING
tIPA_SecondaryWinsServer As IP_ADDR_STRING
tLng_LeaseObtained As Long
tLng_LeaseExpires As Long
End Type
Public Function GetNetworkInfo() As String
Dim lLng_RetVal As Long
Dim lLng_AdapterInfoSize As Long
Dim lTyp_AdapterInfo As IP_ADAPTER_INFO
Dim temp As String
lLng_AdapterInfoSize = 0
lLng_RetVal = GetAdaptersInfo(ByVal 0&, lLng_AdapterInfoSize)
If (lLng_RetVal <> ERROR_BUFFER_OVERFLOW) Then
MsgBox "Unable to get 'GetAdaptersInfo' Size with Error: " & lLng_RetVal
Else
lLng_RetVal = GetAdaptersInfo(lTyp_AdapterInfo, lLng_AdapterInfoSize)
If (lLng_RetVal <> 0) Then
MsgBox "GetAdaptersInfo Failed with Error: " & lLng_RetVal
Else
temp = lTyp_AdapterInfo.tIPA_IpAddressList.tStr_ThisIpAddress
GetNetworkInfo = TrimNull(temp)
End If
End If
End Function
Function TrimNull(str As String) As String
On Error GoTo TN_Err
Dim I As Integer
Dim index As Integer
Dim char As String
Dim char2 As String
char = Right(str, 1)
I = char
index = 1
char2 = Mid(str, Len(str) - index, 1)
While char = char2
index = index + 1
char2 = Mid(str, Len(str) - index, 1)
Wend
TrimNull = Left(str, Len(str) - index)
Exit Function
TN_Err:
If Err = 13 Then
Resume Next
Else
TrimNull = str
End If
End Function