Posts Tagged 系统

VB枚举系统网卡代码

Posted by on 星期一, 28 三月, 2011

  通过枚举系统网卡,获得网卡名称,如果包含”TAP-Win32 Adapter”则说明找到OpenVPN的虚拟网卡。部分代码如下:

Public Function CheckTapDrive() As Long
Dim AdapterInfoSize As Long
Dim AdapterInfo As IP_ADAPTER_INFO
Dim AdapterInfoBuffer() As Byte
Dim ptr1 As Long
On Error GoTo CheckFailed
AdapterInfoSize = 0
Call GetAdaptersInfo(ByVal 0&, AdapterInfoSize)
ReDim AdapterInfoBuffer(AdapterInfoSize - 1)
If 0 = GetAdaptersInfo(AdapterInfoBuffer(0), AdapterInfoSize) Then
ptr1 = VarPtr(AdapterInfoBuffer(0))
Do While (ptr1 <> 0)
CopyMemory AdapterInfo, ByVal ptr1, IP_ADAPTER_INFO_LENGTH

If InStr(AdapterInfo.Description, "TAP-Win32 Adapter") <> 0 Then '此处即是如果找到OpenVPN的TAP虚拟网卡
CheckTapDrive = 1
Exit Function
End If
ptr1 = AdapterInfo.Next
Loop
End If
Exit Function
CheckFailed:
CheckTapDrive = -1
End Function

  完整代码下载:http://www.awolf.net/downloads/enum-network-adapter.zip