rockerBOO rockerBOO - 2 months ago 90
Node.js Question

Express.js req.ip is returning ::ffff:127.0.0.1

I am currently trying to get the IP of the requested user. The problem is the IP is returning

::ffff:127.0.0.1
instead of
127.0.0.1
. I tried using
trusted proxy
option (though not using a proxy) and the
req.ips
is blank. Using 4.x Express.js.

router.get('/', function(req, res, next) {
console.log('ip', req.ip)
res.send({})
});

Answer

Windows 7 has IPv6 enabled by default. Even though my server listens on IPv4 only, Windows 7 sends the ::ffff: prefix to the IPv4 as part of the transition to IPv6

::ffff:0:0:0/96 — A prefix used for IPv4-translated addresses which are used by the Stateless IP/ICMP Translation (SIIT) protocol.

Transition from IPv4