Friday, December 28, 2012

How to get website IP address in ASP.NET


Using the below code you can get the IP address of a website just by passing the URL of the website.

private void GetIPAddress()
{
   //Pass website URL
   string URL = "http://itzonesl.blogspot.com";
  //Remove http://
   string tempUrl = URL.Replace("http://", "").Replace("https://", "").Trim();
  //Split sub domains and get the domain name
   string[] arrURL = tempUrl.Split('/');
   string SiteURL = arrURL[0];
   System.Net.IPAddress[] ip = System.Net.Dns.GetHostAddresses(SiteURL);
   Response.Write(ip[0]);
}


Output:
74.125.235.10

No comments:
Write comments
Recommended Posts × +