I am wanting to get the users IP address (the logged in user will be running the application under there user context on there local PC), but many PC's in our environment have multiple NIC's that have been added by VMWare Workstation, I would like to exclude these type of bridged connections and only show the "primary" NIC on the PC.
The following function will get the IPv4 address, however on my test PC it is returning the bridged connection and not the IP Address of the network facing NIC.
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
My users have a mixture of DHCP and static addresses so cannot limit the NIC to either of these connection types. We tend to have a 172.16.x.x IP range, so is there a way to modify the above function so that it will only return a 172.16.x.x address?
Your assistance is greatly appreciated.
Thanks,
Matt