I know of 2 ways; which I use. To obtain the IP Address of the router if it is a transparent non-anonymous use Request.ServerVariables["HTTP_X_FORWARDED_FOR"]. Secondly, you can use the Request.UserHostAddress if the router is a non-anonymous, non-transparent. Sometimes these values are a bit different, but most of the time they're the same. If the client comes from an anonomous proxy, then you won't be able to get the IP Address.
string userHostAddress = Request.UserHostAddress;
string ipAddress = GetIPAddress();
protected string GetIPAddress()
{
HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ipAddress))
{
string[] addresses = ipAddress.Split(',');
if (addresses.Length != 0)
{
return addresses[0];
}
}
return context.Request.ServerVariables["REMOTE_ADDR"];
}