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

前端 未结 8 726
谎友^
谎友^ 2020-12-02 06:37

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

8条回答
  •  时光取名叫无心
    2020-12-02 07:23

    I was having issues with the trying to compare ipv4 mapped addresses, and found the ipaddr.js library helpful :-)

    eg

    _.isEqual(ipaddr.process('::ffff:127.0.0.1'), ipaddr.process('127.0.0.1')) === true
    

提交回复
热议问题