Using below code you can fetch User's system IP-Address.
Sometime you want to fetch user's IP-Address for monitoring purpose. You can easily get it from current HTTP request. Let's see how to do this.
Simply put this code in your code. Below example useHttpContext.Current.Request to get Current HTTP request.
You can find HttpContext.Current.Request in System.Web namespace.
public class Utility
{
public string GetSystemIPAddress()
{
return HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
}
Let's call this method.
class Program
{
static void Main(string[] args)
{
Console.WriteLine("System IP-Address is:" + new Utility().GetSystemIPAddress());
}
}
Hope this can help you.