【问题标题】:Why does 'socket.handshake.headers['x-forwarded-for'] || socket.handshake.address' result in 2 IP addresses?为什么'socket.handshake.headers['x-forwarded-for'] || socket.handshake.address' 会产生 2 个 IP 地址?
【发布时间】:2018-10-14 10:57:55
【问题描述】:

我正在使用socket.io 获取 IP 地址:

var clientIp = socket.handshake.headers['x-forwarded-for'] || socket.handshake.address
var arr = clientIp.split(":");
var ip = _.last(arr);

ip 变量设置为:"124.202.182.82,100.116.251.26"

为什么在 arr 的最后一个元素中有两个 IP 地址?

【问题讨论】:

    标签: socket.io ip x-forwarded-for


    【解决方案1】:

    在调用split() 时,您使用: 而不是, 作为分隔符。

    X-Forwarded-For 标头中的地址用逗号分隔。

    More information about X-Forwarded-For on MDN

    【讨论】:

      猜你喜欢
      • 2013-10-22
      • 1970-01-01
      • 2017-05-30
      • 2016-05-22
      • 2017-03-17
      • 1970-01-01
      • 2016-02-17
      • 2020-12-16
      相关资源
      最近更新 更多