TextBox1.Text = Request.Url.ToString();
TextBox2.Text = Request.UserHostAddress;
TextBox3.Text = Request.UserHostName;
OR //Add the Namespace
using System.Net;
//Get Visitor IP address method
public string GetVisitorIpAddress()
{
string stringIpAddress;
stringIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (stringIpAddress == null) //may be the HTTP_X_FORWARDED_FOR is null
{
stringIpAddress = Request.ServerVariables["REMOTE_ADDR"];//we can use REMOTE_ADDR
}
return "Your ip is "+stringIpAddress;
}
OR //Get Lan Connected IP address method
public string GetLanIPAddress()
{
//Get the Host Name
string stringHostName = Dns.GetHostName();
//Get The Ip Host Entry
IPHostEntry ipHostEntries = Dns.GetHostEntry(stringHostName);
//Get The Ip Address From The Ip Host Entry Address List
IPAddress[] arrIpAddress = ipHostEntries.AddressList;
return arrIpAddress[arrIpAddress.Length - 1].ToString();
}
OR //Get The Visitor Ip Address
string strVisitorIpAddress = GetVisitorIpAddress();
//Get The Lan Ip Address
string strLanIpAddress = GetLanIPAddress();