1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Google CloudのIPアドレスを調べる方法

Last updated at Posted at 2024-10-20

Google Cloudでは、ネットワークの設定やセキュリティ制御のために、IPアドレス範囲の情報を公開しています。

IPアドレスリストの公式リンク

Googleは、以下のJSONファイルでIPアドレスの範囲を公開しています。

  • Googleサービス用IPアドレスリスト
    https://www.gstatic.com/ipranges/goog.json
    このリストには、Google APIやその他の一般的なGoogleサービス(YouTube、Google Searchなど)のIP範囲が含まれます。

  • Google Cloud用IPアドレスリスト
    https://www.gstatic.com/ipranges/cloud.json
    こちらは、Google Cloud Platform(GCP)のリージョン別IP範囲が詳細に記載されています。

GASでJSONファイルの解析方法

以下のスクリプトは、cloud.jsonを取得し、IPアドレス範囲とリージョン情報をGoogleスプレッドシートに書き込む例です。

function fetchCloudIpRanges() {
  const url = 'https://www.gstatic.com/ipranges/cloud.json';
  
  try {
    // JSONデータの取得
    const response = UrlFetchApp.fetch(url);
    const json = JSON.parse(response.getContentText());

    // スプレッドシートに書き込む準備
    const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    sheet.clear();  // シートの内容をクリア
    sheet.appendRow(['Service', 'Scope', 'IP Range']);  // ヘッダー行を追加

    // JSONデータの解析と書き込み
    json.prefixes.forEach(prefix => {
      const service = prefix.service;
      const scope = prefix.scope;
      const ipRange = prefix.ipv4Prefix || prefix.ipv6Prefix;  // IPv4またはIPv6
      sheet.appendRow([service, scope, ipRange]);
    });

    Logger.log('IPアドレスの取得と書き込みが完了しました。');
  } catch (e) {
    Logger.log('エラーが発生しました: ' + e.toString());
  }
}

image.png

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?