寻找客户端ip express

我正在build立一个基本的networking调查,并希望得到客户的IP地址,通过网站跟踪他们。 我已经看了一些其他的stackoverflow问题,并按照他们的意见,但得到一个奇怪的输出。 从下面的代码:

index.js:

/*POST users*/ router.post('/users', function(req, res, next) { req.body.ip = req.connection.remoteAddress; console.log(req.body); var user = new User(req.body); user.save(function(err,user) { if(err) { return next(err); } res.json(user); }); }); 

我得到这样一个mongo文件:

 "_id" : ObjectId("55cb531714b922ad2478ae9f"), "ip" : "::1", "responses" : [ { "questionId" : "55c9fbb0401a5ba71ce5181a", "optionValue" : 2, "_id" : ObjectId("55cb531714b922ad2478aea1") }, { "questionId" : "55c9fbe90f6fefa91cb4fc2d", "optionValue" : 2, "_id" : ObjectId("55cb531714b922ad2478aea0") } ], "__v" : 0 

任何想法,为什么我可能会得到这个输出?

这是因为::1localhost的IPv6简写 。

你的程序似乎工作正常; 尝试访问从远程计算机的网站,以获得一个正常的IP。