我想获取用户的IP地址(登录的用户将在那里运行应用程序在那里有本地PC上的用户上下文),但我们环境中的许多PC有多个网卡已经由VMWare Workstation添加,我想排除这些类型的桥接连接,并只在PC上显示“主”NIC。用户多个网卡的IP地址
以下函数将获得IPv4地址,但是在我的测试PC上,它将返回桥接连接而不是面向NIC的网络的IP地址。
Shared Function GetIP(ByVal computerName As String) As String
'Dim ipEntry As IPHostEntry = Dns.GetHostEntry(computerName)
'Dim tmpAddr As IPAddress() = ipEntry.AddressList
Dim ipAddress As String = ""
'Dim i As Integer = 0
'Do While i < tmpAddr.Length
' If tmpAddr(i).AddressFamily = Sockets.AddressFamily.InterNetwork Then
' ipAddress = tmpAddr(i).ToString
' End If
' i += 1
'Loop
Dim ipentry As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry("")
For i As Integer = 0 To ipentry.AddressList.Count - 1
ipAddress = System.Net.Dns.GetHostEntry("").AddressList(i).ToString
Next
Return ipAddress
End Function
我的用户混合使用DHCP和静态地址,因此不能将NIC限制为这些连接类型之一。我们倾向于拥有172.16.x.x的IP范围,那么是否有办法修改上述函数,以便它只返回172.16.x.x地址?
非常感谢您的协助。
感谢,
马特
为什么对5岁的问题进行投票? – Lima 2015-11-17 00:36:28