调用下面方法即可获取
// koa2 中 req 为 ctx.req
const getUserIp = (req) => {
return req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
}
websocket 连接时获取
ws.on('connection', function(wsocket) {
const ip = wsocket._socket.remoteAddress;
})
转载于:https://www.cnblogs.com/YMaster/p/9908503.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)