如何从控制器中确定给定请求的IP地址?例如(快递):
app.post('/get/ip/address', function (req, res) {
// need access to IP address here
})
Run Code Online (Sandbox Code Playgroud) 如果我没记错的话,它几天前用于显示"localhost".我不确定是什么改变了使server.address().address返回双冒号(::)而不是.我在这里读到它返回一个IPv6地址(::)如果它可用但它在我的电脑上被禁用了. https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback
任何人都可以告诉我为什么我的服务器地址(主机)是::而不是localhost
var express = require('express');
var app = express();
// respond with "hello world" when a GET request is made to the homepage
app.get('/', function(req, res) {
res.send('hello world');
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('Example app listening at http://%s:%s', host, port);
});
Run Code Online (Sandbox Code Playgroud)
这回来了
Example app listening at http://:::3000
Run Code Online (Sandbox Code Playgroud)
当我去http:// localhost:3000 /时,它工作正常
我想获取一个ip来记录用户登录。
我尝试nestjs-real-ip过并且@Ip()。
我尝试通过手机和电脑浏览器登录,
但他们都表现出来了:::1。如何获取客户端的真实IP?