vb.net – 尝试获取我的IPv4地址获取VirtualBox的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

等等.

…但所有以上给我VirtualBox的IPv4喜欢:

《vb.net – 尝试获取我的IPv4地址获取VirtualBox的IPv4》

为什么这样,我该如何解决?

最佳答案 好吧我没有找到一种方法来获取我想要的ip,但我找到了一种方法来获取所有可用的ips及其网络适配器名称.这是代码,以防任何人想要它:

首先导入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的列表

点赞