ASP.NET get IP address

Last modified: July 17, 2021
Private IP Address
var privateIPAddress = HttpContext.Connection.RemoteIpAddress?.ToString();
Public IP Address
string url = "http://checkip.dyndns.org"; var request = System.Net.WebRequest.Create(url); var getResponse = request.GetResponse(); var reader = new System.IO.StreamReader(getResponse.GetResponseStream()); var response = reader.ReadToEnd().Trim(); var responseArray = response.Split(new Char[] { ':', '<' },StringSplitOptions.RemoveEmptyEntries); var publicIPAddresss = responseArray[6];