Get Client IP address in 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"];
        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

Security Code:
11 + 59
We don't publish your email on our website.