[英]header not revealing the ip address?
{ host: '127.0.0.1:8080',
connection: 'keep-alive',
'cache-control': 'max-age=0',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/44.0.2403.89 Chrome/44.0.2403.89 Safari/537.36',
accept: '*/*',
referer: 'http://127.0.0.1:8080/',
'accept-encoding': 'gzip, deflate, sdch',
'accept-language': 'en-US,en;q=0.8',
cookie: 'io=bP2eXrqS3SkWYY4cAAAC11' }
I am using koa.io from npm to try and get the ip address of the client connecting. 我正在从npm使用koa.io尝试获取连接的客户端的IP地址。 when I try the following code the above is printed in the console.
当我尝试以下代码时,以上内容将打印在控制台中。 I can't seem to get the ip address of the client.
我似乎无法获得客户端的IP地址。
app.io.use(function* userLeft(next) {
// on connect
console.log(this.headers);
});
I am currently on localhost. 我目前在本地主机上。 SO I am expecting the client ip address to be 127.0.0.1?
所以我期望客户端IP地址是127.0.0.1?
Try this.request.ip
. 试试
this.request.ip
。 It should work... 应该可以...
after testing i realized two things. 经过测试,我意识到了两件事。
this.request.ip
to return the client ip, but it isn't. this.request.ip
返回客户端ip,但事实并非如此。 But after configuring my proxy, this.request.header["x-forwarded-for"]
returns the client ip this.request.header["x-forwarded-for"]
返回客户端ip test with this simple server: 用这个简单的服务器测试:
var koa = require('koa');
var app = koa();
app.use(function *(){
this.body = this.request.ip;
});
app.listen(3000);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.