Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我socket.io用来获取IP地址:
socket.io
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地址?
您已用作:分隔符,而不是,在调用split().
:
,
split()
标头中的地址X-Forwarded-For用逗号分隔。
X-Forwarded-For
MDN 上有关 X-Forwarded-For 的更多信息