Firebase功能-客户端IP始终位于Google内部

Firebase功能-客户端IP始终位于Google内部,firebase,google-cloud-functions,Firebase,Google Cloud Functions,我正在编写一个Firebase函数,专门用于Dialogflow聊天机器人的实现。无论如何测试,我都无法获得准确的客户端IP地址 我在各种帖子上看到了读取客户端IP的各种方法,但它们要么是未定义的,要么是来自某个数据中心的内部Google IP 我试着读过: "x-forwarded-for" header req.connection.remoteAddress req.ip req.ips (collection of all of them, there is only

我正在编写一个Firebase函数,专门用于Dialogflow聊天机器人的实现。无论如何测试,我都无法获得准确的客户端IP地址

我在各种帖子上看到了读取客户端IP的各种方法,但它们要么是
未定义的
,要么是来自某个数据中心的内部Google IP

我试着读过:

"x-forwarded-for" header
req.connection.remoteAddress
req.ip
req.ips (collection of all of them, there is only ever 1 in the collection)

任何帮助都将不胜感激。我正在尝试记录有关用户交互的分析,目前IP都不正确。

我尝试了以下提供的代码:


const functions=require('firebase-functions');
const util=require('util');
exports.helloWorld=functions.https.onRequest((req,res)=>{
//对于Firebase托管URI,使用请求头['fastly-client-ip']
//对于可调用函数,使用rawRequest
//一些用户在请求头['x-appengine-user-ip']上的成功率更高
const ipAddress=req.headers['x-forwarded-for']| | req.connection.remoteAddress;
const headers=JSON.stringify(req.headers,null,2);
const message=util.format(“Hello world!\n\n您的IP地址:%s\n\n请求头:%s”,IP地址,头);
res.send(消息);
});
测试时(即使使用移动数据),它返回的是呼叫者的公共IP,而不是谷歌内部IP

如果尝试此操作,是否继续获取内部IP