Tuesday, February 14, 2012

Display IP address of server using ASP.Net

How to display IP address of Server using ASP.NET

Step 1) Make sure internet connection of your machine is available

Step 2)Put the following code in your ASP.Net Page

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;

public partial class socket : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)

            IPHostEntry hostname1 = Dns.GetHostByName("www.google.com");
            IPHostEntry hostname2 = Dns.GetHostByName("www.yahoo.com");
            IPAddress[] ip1 = hostname1.AddressList;
            IPAddress[] ip2 = hostname2.AddressList;

            Response.Write("Google.com:-"+ ip1[0].ToString() + "<br>");
            Response.Write("Yahoo.com"+ ip2[0].ToString());
        catch (Exception ex)

No comments:

Post a Comment