简体   繁体   中英

How do I get the full IP rather than ::1?

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;

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM