'
' Coded by Sharp (sharp_c[dog]yandex[dot]ru)
' 04.09.2005
'
Private Declare Function GetAdaptersInfo
Lib "IPHLPAPI.dll" (
ByRef pAdapterInfo
As Any,
ByRef pOutBufLen
As Long)
As Long
Private Declare Sub CopyMemoryRR
Lib "kernel32.dll"
Alias "RtlMoveMemory" (
ByRef Destination
As Any,
ByRef Source
As Any,
ByVal Length
As Long)
Private Declare Sub CopyMemoryRV
Lib "kernel32.dll"
Alias "RtlMoveMemory" (
ByRef Destination
As Any,
ByVal Source
As Any,
ByVal Length
As Long)
Private Const MAX_ADAPTER_ADDRESS_LENGTH
As Long = 8
Private Const MAX_ADAPTER_DESCRIPTION_LENGTH
As Long = (128 + 4)
Private Const MAX_ADAPTER_NAME_LENGTH
As Long = (256 + 4)
Private Const MAX_IP_STRING_LENGTH
As Long = 16
Private Const MIB_IF_TYPE_OTHER
As Long = 1
Private Const MIB_IF_TYPE_ETHERNET
As Long = 6
Private Const MIB_IF_TYPE_TOKENRING
As Long = 9
Private Const MIB_IF_TYPE_FDDI
As Long = 15
Private Const MIB_IF_TYPE_PPP
As Long = 23
Private Const MIB_IF_TYPE_LOOPBACK
As Long = 24
Private Const MIB_IF_TYPE_SLIP
As Long = 28
'typedef struct _IP_MASK_STRING{
' char String[4 * 4];
'};
Private Type IP_MASK_STRING
s
As String * MAX_IP_STRING_LENGTH
End Type
'typedef struct _IP_ADDRESS_STRING{
' char String[4 * 4];
'};
Private Type IP_ADDRESS_STRING
s
As String * MAX_IP_STRING_LENGTH
End Type
'typedef struct _IP_ADDR_STRING{
' struct _IP_ADDR_STRING* Next;
' IP_ADDRESS_STRING IpAddress;
' IP_MASK_STRING IpMask;
'  WORD Context;
'};
Private Type IP_ADDR_STRING
lpNext
As Long
IpAddress
As IP_ADDRESS_STRING
IpMask
As IP_MASK_STRING
Context
As Long
End Type
'typedef struct _IP_ADAPTER_INFO{
' struct _IP_ADAPTER_INFO* Next;
'  WORD ComboIndex;
' char AdapterName[MAX_ADAPTER_NAME_LENGTH + 4];
' char Description[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];
' UINT AddressLength;
' BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH];
'  WORD Index;
' UINT Type;
' UINT DhcpEnabled;
' PIP_ADDR_STRING CurrentIpAddress;
' IP_ADDR_STRING IpAddressList;
' IP_ADDR_STRING GatewayList;
' IP_ADDR_STRING DhcpServer;
' BOOL HaveWins;
' IP_ADDR_STRING PrimaryWinsServer;
' IP_ADDR_STRING SecondaryWinsServer;
' time_t LeaseObtained;
' time_t LeaseExpires;
'};
Private Type IP_ADAPTER_INFO
lpNext
As Long
ComboIndex
As Long
AdapterName
As String * MAX_ADAPTER_NAME_LENGTH
 
escription
As String * MAX_ADAPTER_DESCRIPTION_LENGTH
AddressLength
As Long
Address
As String * MAX_ADAPTER_ADDRESS_LENGTH
Index
As Long
Type As Long
 
hcpEnabled
As Long
CurrentIpAddress
As Long
IpAddressList
As IP_ADDR_STRING
GatewayList
As IP_ADDR_STRING
 
hcpServer
As IP_ADDR_STRING
HaveWins
As Integer
PrimaryWinsServer
As IP_ADDR_STRING
SecondaryWinsServer
As IP_ADDR_STRING
LeaseObtained
As Long
LeaseExpires
As Long
End Type
Private Sub Command1_Click()
Text1 = GetAdaptersInformation()
End Sub
Private Function GetAdaptersInformation()
As String
Dim buff()
As Byte
Dim pLen
As Long
Dim iai
As IP_ADAPTER_INFO
Dim res
As String
Dim lNext
As Long
pLen = 0
GetAdaptersInfo
Null, pLen
If pLen = 0
Then
GetAdaptersInformation = "No adapters" & vbCrLf
Else
ReDim buff(pLen)
GetAdaptersInfo buff(0), pLen
CopyMemoryRR iai, buff(0), 640
res = res & GetAdapterInformation(iai)
Do While iai.lpNext <> 0
lNext = iai.lpNext
CopyMemoryRV iai, lNext, 640
res = res & GetAdapterInformation(iai)
Loop
GetAdaptersInformation = res
End If
End Function
Private Function GetAdapterInformation(iai
As IP_ADAPTER_INFO)
As String
Dim res
As String
res = res & "Adapter: " & sz2String(iai.AdapterName) & vbCrLf
res = res & "
escription: " & sz2String(iai.Description) & vbCrLf
res = res & "Phys.address: " & String2PhysAddr(iai.Address, iai.AddressLength) & vbCrLf
res = res & "Index: " &
CStr(iai.Index) & vbCrLf
Select Case iai.
Type
Case MIB_IF_TYPE_OTHER: res = res & "
Type: Other" & vbCrLf
Case MIB_IF_TYPE_ETHERNET: res = res & "
Type: Ethernet" & vbCrLf
Case MIB_IF_TYPE_TOKENRING: res = res & "
Type: TokenRing" & vbCrLf
Case MIB_IF_TYPE_FDDI: res = res & "
Type: FDDI" & vbCrLf
Case MIB_IF_TYPE_PPP: res = res & "
Type: PPP" & vbCrLf
Case MIB_IF_TYPE_LOOPBACK: res = res & "
Type: Loopback" & vbCrLf
Case MIB_IF_TYPE_SLIP: res = res & "
Type: SLIP" & vbCrLf
End Select
res = res & "
HCP server: "
If iai.DhcpEnabled
Then
res = res & sz2String(iai.DhcpServer.IpAddress.s) & vbCrLf
res = res & "
HCP obtained: " &
CStr(DateAdd("s", iai.LeaseObtained, "01.01.1970"
) & vbCrLf
res = res & "
HCP expires: " &
CStr(DateAdd("s", iai.LeaseExpires, "01.01.1970"
) & vbCrLf
Else
res = res & "No" & vbCrLf
End If
res = res & "
efault gateway: " & sz2String(iai.GatewayList.IpAddress.s) & vbCrLf
res = res & "IP address: " & GetIPList(iai.IpAddressList) & vbCrLf
res = res & "WINS: "
If iai.HaveWins
Then
res = res & "primary - " & sz2String(iai.PrimaryWinsServer.IpAddress.s) & "; " & _
"secondary - " & sz2String(iai.PrimaryWinsServer.IpAddress.s) & vbCrLf
Else
res = res & "No" & vbCrLf
End If
GetAdapterInformation = res & vbCrLf
End Function
Private Function String2PhysAddr(Addr
As String, AddrLen
As Long)
Dim res
As String
Dim s
As String
For i = 1
To AddrLen
s = Hex(Asc(
Mid(Addr, i, 1)))
res = res & IIf(
Len(s) = 1, "0", ""
& s & "-"
Next
String2PhysAddr = Left(res,
Len(res) - 1)
End Function
Private Function GetIPList(ipl
As IP_ADDR_STRING)
As String
Dim lNext
As Long
Dim res
As String
Dim ias
As IP_ADDR_STRING
CopyMemoryRR ias, ipl, 40
res = res & sz2String(ias.IpAddress.s) & "/" & sz2String(ias.IpMask.s) & "; "
Do While ias.lpNext <> 0
lNext = ias.lpNext
CopyMemoryRV ias, lNext, 40
res = res & sz2String(ias.IpAddress.s) & "/" & sz2String(ias.IpMask.s) & "; "
Loop
GetIPList = Left(res,
Len(res) - 2)
End Function
Private Function sz2String(s
As String)
As String
sz2String = Left(s, InStr(s, vbNullChar) - 1)
End Function