1
Good evening, everyone
I made a web application with ASPNET and C#, and I need to get the user’s IP when he accesses the system.
I researched if I found several ways, but I always have this return::1
Follows below the code used:
Response.Write(Request.ServerVariables["REMOTE_Host"].ToString());
I searched here on Stackoverflow and found the code below, but returns me the ip from where the request is hosted:
public static string GetPublicIP()
{
string url = "http://checkip.dyndns.org";
System.Net.WebRequest req = System.Net.WebRequest.Create(url);
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd().Trim();
string[] a = response.Split(':');
string a2 = a[1].Substring(1);
string[] a3 = a2.Split('<');
string a4 = a3[0];
return a4;
}
I don’t know what else to do.
So, guys. How do I get the public ip of the user who accessed my system?
Vlw..
What version of . net? Core or "full framework"?
– tvdias
.NET 4.6.1, Webform
– Rodrigo Storti de Oliveira
This return not because you are running the application locally on your machine?
– Leandro Angelo
Do you want whose IP? The user who is accessing the application or the machine that is running the application (your server)?
– Jéf Bueno
I want the IP address of who is accessing the application.
– Rodrigo Storti de Oliveira