ARTICLE

Get IP Address of a HOST in VB.NET

Posted by Mahesh Chand Articles | Visual Basic 2010 June 26, 2003
The .Net DNS class can be used to get a host name or an IP of a given host name. To use DNS class in your project, you need to include System.Net.
 
Reader Level:

The .Net DNS class can be used to get a host name or an IP of a given host name. To use DNS class in your project, you need to include System.Net.

Include System.Net Reference.

And say I want to get IP address if
http://www.dotnetheaven.com/. The given code will do that for you.

Imports System
Imports System.Net
Namespace DNSName
' <summary>
' Summary description for Class1.
' </summary>
Class Class1
'Entry point which delegates to C-style main Private Function
Public Overloads Shared Sub Main()
Main(System.Environment.GetCommandLineArgs())
End Sub
Overloads
Shared Sub Main(args() As String)
Dim ipEntry As IPHostEntry = Dns.GetHostByName(http://www.dotnetheaven.com/)
Dim IpAddr As IPAddress() = ipEntry.AddressList
Dim i As Integer
For
i = 0 To IpAddr.Length - 1
Console.WriteLine("IP Address {0}: {1} ", i, IpAddr(i).ToString())
Next i
End Sub 'Main
End Class 'Class1
End Namespace 'DNSName

share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Diagram
Become a Sponsor