试图获取我的IPv4地址获取VirtualBox的IPv4

时间:2016-09-26 19:22:14

标签: vb.net 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

E.t.c。

...但是所有以上给我VirtualBox的IPv4赞:

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

1 个答案:

答案 0 :(得分:2)

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

首先导入System.Net.SocketsSystem.NetSystem.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的列表