Get Client IP address in asp.net C#

IP address (Internet Protocol) is an identifying number that is associated with a specific computer or network. IP address allow to the computers to send and receive information when connected to the internet.
public static string GetIPAddress()
{
    string ipAddress = string.Empty;
    ipAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
    if(string.IsNullOrEmpty(ipAddress))
  {
        ipAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
        ipAddress = ipAddress.Replace("::ffff:", "");
        ipAddress = ipAddress.Replace("::1", "");
  }
    return ipAddress;
}
Note: You can not get IP address on local host.

 Posted Comments

No comments have been posted to this article.

 Post a comment

Name:
Email:
Comment:
Security Code:
26 + 33
=
We don't publish your email on our website.