如何从 IBM Cloud 函数获取远程 IP

How to get remote IP from IBM Cloud functions

我正在 IBM Cloud 上编写无服务器功能;我的代码需要根据远程 IP 采取行动,按国家/地区过滤请求。如何获取连接详细信息,例如 Express req.ip 或 Node request.connection.remoteAddress?

我最近就此联系了 IBM Cloud 支持。他们说还不支持。

While testing Cloud Functions, I wanted to check if I could use the IP address of the client to do geolocation. This is a use case I have at my work (we don't use IBM Cloud right now, we use GKE). I noticed by making a test function that I was able to log the headers when I made it a web action. I noticed that there were two headers that appeared to contain the IP address of the client (my web browser), but it's not the right IP. My IP right now is ... but the headers X-Forwarded-For and X-Real-IP contained the IP 172.70.130.199, according to the logs in LogDNA.

他们的回复:

Thank you for your patience and functions team confirmed this is not supported yet, and this has been submitted to dev team to review to add to the dev pipeline. Sorry for your inconvenience and feel free to let us know if you have more concerns.