Why is req.ip in node/Express returning colon separated IP addresses?

五迷三道 提交于 2021-01-27 14:57:36

问题


I am trying to log the remote client IP. Sounds elementary and Express provides the "ip" property on the request object, as in req.ip, to get this info. Also, there is req.ips to get multiple IP addresses from X-Forwarded-For where proxies are involved. I also tried the npm module request-ip. My question is that they all return client IP addresses as in

 ::ffff:A.B.C.D

where A.B.C.D is indeed the address I am looking for. But, my question is: what are the prefixes there? I can understand req.ips or X-Forwarded-For returning multiple IP addresses but even there I would expect real IP addresses not nulls.

Of course I can get the last address but I want to know what the colon-separated blank entries mean even when trying to get just the single req.ip address?


回答1:


The double colon :: is a shortcut in IPv6 to indicate a string of zeros as spoken of in this Server Fault question. The first part ::fff: is a prefix for IPv4 address that are embedded in an IPv6 address as part of the transition to IPv6.

::ffff:A.B.C.D
--v6-- --v4--


来源:https://stackoverflow.com/questions/33120858/why-is-req-ip-in-node-express-returning-colon-separated-ip-addresses

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!