using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ltrlSystemDetails.Text = string.Empty;
string machineName = Dns.GetHostName();
ltrlSystemDetails.Text += "Machine Name : " + machineName + "<br/>";
ltrlSystemDetails.Text += "IP Address : " + GetIP(machineName) + "<br/>";
ltrlSystemDetails.Text += "Local IP Address : " + GetIP4Address();
}
private string GetIP(string _machineName)
{
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(_machineName);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length-1].ToString();
}
public string GetIP4Address()
{
string IP4Address = String.Empty;
foreach (IPAddress IPA in Dns.GetHostAddresses(Request.ServerVariables["REMOTE_ADDR"].ToString()))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
if (IP4Address != String.Empty)
{
return IP4Address;
}
foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (IPA.AddressFamily.ToString() == "InterNetwork")
{
IP4Address = IPA.ToString();
break;
}
}
return IP4Address;
}
}