Reputation: 752
I Tried Everything To Get My IPv4 Address ...
Some Examples:
Dim s As String = Dns.GetHostEntry(Dns.GetHostName()).AddressList.Where(Function(a As IPAddress) Not a.IsIPv6LinkLocal AndAlso Not a.IsIPv6Multicast AndAlso Not a.IsIPv6SiteLocal).First().ToString()
_
Dim myClientMachineAddressList As IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName())
Dim myClientMachineIP As String = myClientMachineAddressList.AddressList(0).ToString()
_
strHostName = System.Net.Dns.GetHostName()
strIPAddress = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()
_
Dim entry = Dns.GetHostEntry(System.Net.Dns.GetHostName())
For Each address In entry.AddressList
If address.AddressFamily = AddressFamily.InterNetwork Then
Return address.ToString
End If
Next
E.t.c.
... But All The Above Give Me VirtualBox's IPv4 Like:
Why is that and how can I fix it?
Upvotes: 4
Views: 607
Reputation: 752
Ok I didn't find a way to get the ip I wanted, but i found a way to get all the available ips with their network adapter name. Here is the code in case anyone wants it:
First Import System.Net.Sockets
, System.Net
And System.Net.NetworkInformation
The code:
Dim lst As New List(Of String)
For Each adapter As NetworkInterface In NetworkInterface.GetAllNetworkInterfaces
lst.Add(adapter.Description & ": " & adapter.GetIPProperties.UnicastAddresses(1).Address.ToString)
Next
lst
is the list with all the network adapters and their ips
Upvotes: 2