Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  Windows Development  »  Enumerating IP Addresses of a Local Machine Using VB.NET
Enumerating IP Addresses of a Local Machine Using VB.NET
by Deepak Sharma | Published  03/09/2003 | Windows Development | Rating:
Deepak Sharma

Deepak Sharma is currently working for Tata Infotech Ltd in the role of Systems Specialist and is involved in consulting and system integration projects throughout the world. Deepak is a Microsoft Certified Professional with more than 5 years of experience developing world class intranet and internet applications. He has previously worked for GE Appliances, InterActual Inc and is currently based in Columbus, OH, USA working for National City Bank. Deepak also maintains his personal website and weblog at He also has a .NET weblog


View all articles by Deepak Sharma...
Enumerating IP Addresses of a Local Machine Using VB.NET

Article source code:

Now and then this question is asked on various .NET newsgroups on how to list all the IP addresses machine is using. .NET Framework Class Library contains System.Net namespace that provides a simple programming interface for many of the protocols used on networks today. This namespace contains Dns class that provides simple domain name resolution functionality. The Dns class is static class that retrieves information about specific host from the Internet Domain Name System (DNS). The host information from the DNS query is returned in an instance of the IPHostEntry class. If the specified host has more than one entry in the DNS database, IPHostEntry contains multiple IP addresses and aliases.

The following code snippet shows how to enumerate all the IP addresses associated with machine using Visual Basic.NET.

Imports System
Imports System.Net

Module Module1

    Sub Main()
        Dim strMachineName As String

        'Get the Host Name
        strMachineName = Dns.GetHostName()
        Console.WriteLine("Host Name: " + strMachineName)

        'Get the Host by Name
        Dim ipHost As IPHostEntry
        ipHost = Dns.GetHostByName(strMachineName)

        'You can also query the DNS database for info on a 
        'website like
        'In that case replace the above line as:
        'ipHost = Dns.GetHostByName("")

        'Get the list of addresses associated with the host in an array
        Dim ipAddr() As IPAddress = ipHost.AddressList
        Dim count As Integer

        'Enumerate the IP Addresses
        For count = 0 To ipAddr.GetUpperBound(0)
            Console.Write("IP Addresses {0}: {1} "count_
    End Sub

End Module
Generated using PrettyCode.Encoder
How would you rate the quality of this article?
1 2 3 4 5
Poor Excellent
Tell us why you rated this way (optional):

Article Rating
The average rating is: No-one else has rated this article yet.

Article rating:1.68354430379744 out of 5
 395 people have rated this page
Article Score77596
Sponsored Links