Convert Domain Name to I.P Address

A user asked me on the forums if it was possible to convert a domain name to an I.P. Address. The answer is quiet simple. Just use the System.Net.Dns class

C#


using System.Net;

protected void Page_Load(object sender, EventArgs e)

{

    foreach (IPAddress address in 

        Dns.GetHostAddresses("www.devcurry.com"))

    {  

        Response.Write(address.ToString());

    }

}



VB.NET


Imports System.Net

Protected Sub Page_Load(ByVal sender As Object, _

                     ByVal e As EventArgs)

    For Each address As IPAddress In 

    Dns.GetHostAddresses("www.devcurry.com")

        Response.Write(address.ToString())

    Next address

End Sub






About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

1 comment:

Anonymous said...
This comment has been removed by the author.