當連接到不同的VPN時,我做了一些挖掘。到目前爲止,下面看起來非常可靠。在上面建議的實際物理適配器依賴於0或1在許多情況下不起作用。在某些情況下,我的實際以太網適配器是第三個適配器排除環回,隧道和ppp適配器應縮小範圍。我發現很多非物理適配器都將字符串「00000000000000E0」作爲mac地址。
Private Function getMacAddress() As String
Try
Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()
Dim adapter As NetworkInterface
Dim myMac As String = String.Empty
For Each adapter In adapters
Select Case adapter.NetworkInterfaceType
'Exclude Tunnels, Loopbacks and PPP
Case NetworkInterfaceType.Tunnel, NetworkInterfaceType.Loopback, NetworkInterfaceType.Ppp
Case Else
If Not adapter.GetPhysicalAddress.ToString = String.Empty And Not adapter.GetPhysicalAddress.ToString = "00000000000000E0" Then
myMac = adapter.GetPhysicalAddress.ToString
Exit For ' Got a mac so exit for
End If
End Select
Next adapter
Return myMac
Catch ex As Exception
Return String.Empty
End Try
End Function
也許你沒有安裝正確的.Net框架? – Yohannes
謝謝,我已經改變了nics(1)到nics(0),,它現在的作品 – Ali