0

I have tried to get ip address of client but I just get ip of server, There is a way to get it? please, I want a function in the controller to get ip of client.

public static string GetIP()
{
  var host = Dns.GetHostEntry(Dns.GetHostName());
  foreach (var ip in host.AddressList)
  {
    if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
    {
      return ip.ToString();
    }
  }
  throw new Exception("No network adapters with an IPv4 address in the system!");
}
daniela
  • 43
  • 1
  • 1
  • 7
  • 2
    Possible duplicate of [How to get a user's client IP address in ASP.NET?](https://stackoverflow.com/questions/735350/how-to-get-a-users-client-ip-address-in-asp-net) – maccettura Oct 02 '18 at 20:10
  • I tried this but it just give me ip server or this "::1" not ip of the client – daniela Oct 02 '18 at 20:18
  • That's ipv6 loopback, which means most likely your client and server on the same machine. – mtmk Oct 02 '18 at 20:39

0 Answers0