开发者

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] is returning IPv6

开发者 https://www.devze.com 2023-04-03 02:33 出处:网络
Microsoft\'s HttpContext.Current.Request.ServerV开发者_如何学运维ariables[\"REMOTE_ADDR\"] is returning IPv6 for the remote client. However, I need to use this data for a session logging table where t

Microsoft's HttpContext.Current.Request.ServerV开发者_如何学运维ariables["REMOTE_ADDR"] is returning IPv6 for the remote client. However, I need to use this data for a session logging table where the ClientIP column is varchar(15)... IOW, I need the IPv4 client IP address as IPv6 throws a string truncation error.

Is this doable?


No, the IPv4 and IPv6 addresses of a client are completely unrelated, so you cannot find someone's IPv4 address when they connect over IPv6. Maybe they don't even have an IPv4 address... Or at least not an IPv4 address that is unique. More and more ISPs will start to share IPv4 addresses between customers because they don't have enough IPv4 addresses to give every user his own. That also means that a user's IPv4 address can change over time, if the IPv4 address comes out of a pool of addresses that customers share.

You could try to make the user connect over IPv4 of course. But like I said: no guarantee that that will give you something useful. And in the (near) future it will become worse...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号