尝试获取我的 IPv4 地址获取 VirtualBox 的 IPv4
Trying to get my IPv4 address gets VirtualBox's IPv4
我已尽一切努力获取我的 IPv4 地址...
一些例子:
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.
...但是以上所有都给我 VirtualBox 的 IPv4 喜欢:
为什么会这样,我该如何解决?
好的,我没有找到获取所需 ip 的方法,但我找到了获取所有可用 ip 及其网络适配器名称的方法。这是代码,以防有人需要它:
首先导入 System.Net.Sockets
,System.Net
和 System.Net.NetworkInformation
代码:
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
是包含所有网络适配器及其 ips 的列表
我已尽一切努力获取我的 IPv4 地址...
一些例子:
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.
...但是以上所有都给我 VirtualBox 的 IPv4 喜欢:
为什么会这样,我该如何解决?
好的,我没有找到获取所需 ip 的方法,但我找到了获取所有可用 ip 及其网络适配器名称的方法。这是代码,以防有人需要它:
首先导入 System.Net.Sockets
,System.Net
和 System.Net.NetworkInformation
代码:
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
是包含所有网络适配器及其 ips 的列表