Wednesday, October 12, 2011

Get Current Pc IP Address in Asp.Net

string IP = HttpContext.Current.Request.UserHostAddress+ '-' + Request.Browser.Platform.ToString() + '-' + Request.Browser.Browser.ToString() + '-' + System.Net.Dns.GetHostName() + '-' + DateTime.Now + DateTime.Now.Minute + DateTime.Now.Millisecond + "-" + strName;

protected string GetLocalPCIP()
{
string LocalIP = null;
System.Net.IPHostEntry IPHostEntry = System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName());
foreach (System.Net.IPAddress IPAddress in IPHostEntry.AddressList)
{
if (IPAddress.AddressFamily.ToString() == "InterNetwork")
{
LocalIP = IPAddress.ToString();
}
}
return LocalIP;
}

No comments:

Post a Comment