LoginSignup
2
2

More than 5 years have passed since last update.

Azure仮想マシンのIPアドレス一覧をAPIで取得

Posted at

概要

Azure上の仮想マシンは、Web APIで一覧を取得できます。
Azureにデプロイしたシステムと、Azure外の社内システムなんかを連携させたい場合なんかは、このAPIで取得したIPのみ社内システムに許可させるとかできます。
ウチでは、Azure Functionsからのリクエストを社内システムに通すために、これを使っています。

リクエスト方法

↓にPOSTします。
https://azuredcip.azurewebsites.net/api/azuredcipranges

bodyには、JSONで条件を指定します。
条件の指定方法は後述。とりあえずcurlするとこんな感じ(Windowsでもcurlできるようになったよ!)。

curl -X POST -H "Content-Type: application/json" -d "{'region':'all', 'request':'dcip'}" https://azuredcip.azurewebsites.net/api/azuredcipranges

全IPの一覧

とりあえず、手っ取り早くIPの一覧を得るには、bodyに下記を指定してください。

{"region":"all", "request":"dcip"}

regionごとに、CIDR表記でIPの一覧が返ってきます。

{
  "uswest" : [
    "13.64.0.0/16",
    "13.73.32.0/19",
    "13.83.0.0/16",
    "13.86.128.0/17",
    "13.87.128.0/17",
    "13.88.0.0/17",
    "13.88.128.0/18",
    "13.88.192.0/23",
  :

regionの一覧

regionの一覧が欲しい場合は、下記。
regionパラメータは指定しても良いですが、無視されます。

{"request":"dcnames"}

結果。

[
  "australiac2",
  "australiac",
  "australiaeast",
  "australiasoutheast",
  "brazilsouth",
  "canadacentral",
  "canadaeast",
  "indiacentral",
  "uscentraleuap",
  "uscentral",
  "asiaeast",
  "europeeast",
  "useast2euap",
  "useast2",
   :

regionごとの一覧

特定のregionについてのIPが欲しければ、regionパラメータに指定します。

{"region":"japaneast", "request":"dcip"}

結果。

{
  "japaneast" : [
    "13.71.128.0/19",
    "13.73.0.0/19",
    "13.78.0.0/17",
    "20.37.96.0/19",
    "20.38.116.0/23",
   :

参考になったサイト

Azure: Get Datacenter IP address ranges via API

2
2
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
2
2