0

I have wrote this to get client's ip address but it just gets this ::1 instead of 172.16.0.129. I want to get Ipv4 version of the ip. How do I do this?

return HttpContext.Current.Request.Params["HTTP_CLIENT_IP"] ?? HttpContext.Current.Request.UserHostAddress;
mjwills
  • 23,389
  • 6
  • 40
  • 63

1 Answers1

1

In IPv6 ::1 means the localhost. Your machine might well have the IP 172.16.0.129 but it's also perfectly acceptable for it to refer to itself as ::1

Try your request from another machione (I suspect this request came from the same machine as the server is sitting on)

Caius Jard
  • 72,509
  • 5
  • 49
  • 80
  • alright but I want to get the ipv4 version even for localhost – Posting Questions Oct 18 '18 at 08:42
  • I'm not sure that coding your software up to only deal with ipv4 is going to make it particularly resilient.. But if you make a request from another machine, and that other machine communciates with yours over ipv4 then the IP you see when pulling the http headers will likely be the ipv4 version – Caius Jard Oct 18 '18 at 09:24