public class HomeController : Controller
{
    // GET: Home
    public ActionResult Index()
    {
        string ipAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (string.IsNullOrEmpty(ipAddress))
        {
            ipAddress = Request.ServerVariables["REMOTE_ADDR"];
        }
        ViewBag.IPAddress = ipAddress;
 
        return View();
    }
}

Get IP Address In ASP.NET

https://www.c-sharpcorner.com/article/get-ip-address-in-Asp-Net/