Enumerate Network adapters

Download source code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim strMachineName As String
 
    'Get the Host Name
    strMachineName = Dns.GetHostName()
 
    'Get the Host by Name
    Dim ipHost As IPHostEntry
    ipHost = Dns.GetHostEntry(strMachineName)
 
    'You can also query the DNS database for info on a
    'website like www.microsoft.com
    'In that case replace the above line as:
    'ipHost = Dns.GetHostByName("www.microsoft.com")
 
    'Get the list of addresses associated with the host in an array
    Dim ipAddr() As IPAddress = ipHost.AddressList
    Dim count As Integer
 
    ListBox1.Items.Clear()
    'Enumerate the IP Addresses
    Dim addr As IPAddress
 
    For count = 0 To ipAddr.GetUpperBound(0)
        addr = ipAddr(count)
        ListBox1.Items.Add(String.Format("IP Addresses {0}: {1}", count, addr.ToString))
    Next
End Sub

Add Feedback