To achieve this use below line of code:

  1. string IPAddress = string.Empty;
  2. IPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
  3. if (IPAddress == "" || IPAddress == null)
  4. IPAddress = Request.ServerVariables["REMOTE_ADDR"];
  5. Response.Write("<b>Your Machine IP Address is: </b>" + IPAddress);

Image 1.