Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 688
Sunny Avatar asked Oct 14 '15 08:10

Sunny


1 Answers

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--
like image 156
carpenter Avatar answered Sep 29 '22 16:09

carpenter