展开全部
Option Explicit
Private Const NO_ERROR As Long = 0
Private Const MAX_ADAPTER_NAME As Long = 256
Private Type IP_ADAPTER_INDEX_MAP
Index As Long
wsName As String * MAX_ADAPTER_NAME
End Type
Private Type IP_INTERFACE_INFO
NumAdapters As Long
Adapter(0) As IP_ADAPTER_INDEX_MAP
End Type
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function IpReleaseAddress Lib "IPHLPAPI.dll" (ByRef AdapterInfo As IP_ADAPTER_INDEX_MAP) As Long
Private Declare Function IpRenewAddress Lib "IPHLPAPI.dll" (ByRef AdapterInfo As IP_ADAPTER_INDEX_MAP) As Long
Private Declare Function GetInterfaceInfo Lib "IPHLPAPI.dll" (ByRef pIfTable As Any, ByRef dwOutBufLen As Long) As Long
Private Sub Command1_Click()
Dim i As Long, lOut As Long, lNum As Long
Dim III As IP_INTERFACE_INFO, arrTmp() As Byte
Dim aIAIM() As IP_ADAPTER_INDEX_MAP, IAIM As IP_ADAPTER_INDEX_MAP
i = GetInterfaceInfo(III, lOut)
ReDim arrTmp(lOut - 1)
i = GetInterfaceInfo(arrTmp(0), lOut)
If i <> NO_ERROR Then Exit Sub
CopyMemory lNum, arrTmp(0), 4
Debug.Print lNum; " Network Interface(s) Total!!!"
ReDim aIAIM(lNum - 1)
For i = 0 To lNum - 1
CopyMemory aIAIM(i), arrTmp(4 + i * Len(IAIM)), Len(IAIM)
Debug.Print "Index:"; aIAIM(i).Index; " Name:"; StrConv(aIAIM(0).wsName, vbFromUnicode)
Next
Debug.Print IpReleaseAddress(aIAIM(0)) '断开第一个网卡
End Sub
Private Sub Command2_Click()
Dim i As Long, lOut As Long, lNum As Long
Dim III As IP_INTERFACE_INFO, arrTmp() As Byte
Dim aIAIM() As IP_ADAPTER_INDEX_MAP, IAIM As IP_ADAPTER_INDEX_MAP
i = GetInterfaceInfo(III, lOut)
ReDim arrTmp(lOut - 1)
i = GetInterfaceInfo(arrTmp(0), lOut)
If i <> NO_ERROR Then Exit Sub
CopyMemory lNum, arrTmp(0), 4
Debug.Print lNum; " Network Interface(s) Total!!!"
ReDim aIAIM(lNum - 1)
For i = 0 To lNum - 1
CopyMemory aIAIM(i), arrTmp(4 + i * Len(IAIM)), Len(IAIM)
Debug.Print "Index:"; aIAIM(i).Index; " Name:"; StrConv(aIAIM(0).wsName, vbFromUnicode)
Next
Debug.Print IpRenewAddress(aIAIM(0)) '恢复第一个网卡
End Sub
禁用/恢复指定网卡。。。
************************************************************
都是API的用法哈。。。。没什么好解释的 = =!抱歉。。。。
Private Const NO_ERROR As Long = 0
Private Const MAX_ADAPTER_NAME As Long = 256
Private Type IP_ADAPTER_INDEX_MAP
Index As Long
wsName As String * MAX_ADAPTER_NAME
End Type
Private Type IP_INTERFACE_INFO
NumAdapters As Long
Adapter(0) As IP_ADAPTER_INDEX_MAP
End Type
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByRef Destination As Any, ByRef Source As Any, ByVal Length As Long)
Private Declare Function IpReleaseAddress Lib "IPHLPAPI.dll" (ByRef AdapterInfo As IP_ADAPTER_INDEX_MAP) As Long
Private Declare Function IpRenewAddress Lib "IPHLPAPI.dll" (ByRef AdapterInfo As IP_ADAPTER_INDEX_MAP) As Long
Private Declare Function GetInterfaceInfo Lib "IPHLPAPI.dll" (ByRef pIfTable As Any, ByRef dwOutBufLen As Long) As Long
Private Sub Command1_Click()
Dim i As Long, lOut As Long, lNum As Long
Dim III As IP_INTERFACE_INFO, arrTmp() As Byte
Dim aIAIM() As IP_ADAPTER_INDEX_MAP, IAIM As IP_ADAPTER_INDEX_MAP
i = GetInterfaceInfo(III, lOut)
ReDim arrTmp(lOut - 1)
i = GetInterfaceInfo(arrTmp(0), lOut)
If i <> NO_ERROR Then Exit Sub
CopyMemory lNum, arrTmp(0), 4
Debug.Print lNum; " Network Interface(s) Total!!!"
ReDim aIAIM(lNum - 1)
For i = 0 To lNum - 1
CopyMemory aIAIM(i), arrTmp(4 + i * Len(IAIM)), Len(IAIM)
Debug.Print "Index:"; aIAIM(i).Index; " Name:"; StrConv(aIAIM(0).wsName, vbFromUnicode)
Next
Debug.Print IpReleaseAddress(aIAIM(0)) '断开第一个网卡
End Sub
Private Sub Command2_Click()
Dim i As Long, lOut As Long, lNum As Long
Dim III As IP_INTERFACE_INFO, arrTmp() As Byte
Dim aIAIM() As IP_ADAPTER_INDEX_MAP, IAIM As IP_ADAPTER_INDEX_MAP
i = GetInterfaceInfo(III, lOut)
ReDim arrTmp(lOut - 1)
i = GetInterfaceInfo(arrTmp(0), lOut)
If i <> NO_ERROR Then Exit Sub
CopyMemory lNum, arrTmp(0), 4
Debug.Print lNum; " Network Interface(s) Total!!!"
ReDim aIAIM(lNum - 1)
For i = 0 To lNum - 1
CopyMemory aIAIM(i), arrTmp(4 + i * Len(IAIM)), Len(IAIM)
Debug.Print "Index:"; aIAIM(i).Index; " Name:"; StrConv(aIAIM(0).wsName, vbFromUnicode)
Next
Debug.Print IpRenewAddress(aIAIM(0)) '恢复第一个网卡
End Sub
禁用/恢复指定网卡。。。
************************************************************
都是API的用法哈。。。。没什么好解释的 = =!抱歉。。。。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询