如何在 Google Apps Script 中知道 UrlFetchApp 的 IP?

问题描述

我在 Stackoverflow 上搜索过类似的问题,但他们没有给出答案。

我向某些 api 服务发出 UrlFetchApp.fetch(url) 请求,但该服务可能禁止此请求 IP。我需要将其列入白名单。我知道谷歌应用程序使用了很多 IP,但现在我需要至少确定用于此特定调用的 IP。

我尝试了这个脚本来找出请求:

function getR(){
  var url = 'https://my.APIENDPOINTURL'
  req = UrlFetchApp.getRequest(url,options)
  Logger.log(req)
  resp = UrlFetchApp.fetch(url,options)
  Logger.log(resp)
}

它给了我这个日志:

enter image description here

为什么会显示我的真实IP?

幕后发生了什么?我希望在 .getRequests() 输出中使用 UrlFetchApp 的真实 IP。 我错过了什么吗?

知道UrlFetchApp使用哪个IP有什么技巧吗? 我知道没有此功能作为本机功能

解决方法

您可以在此处找到 Apps 脚本在调用其他服务时可能使用的 IP 地址列表 - https://www.gstatic.com/ipranges/goog.txt

它被埋在这个 JDBC article 中。