LoginSignup
2
0

More than 5 years have passed since last update.

AWS EC2 でグローバルIPアドレスを取得

Last updated at Posted at 2019-01-08

EC2 でグローバルアドレスを取得する方法です。

A) Curl

get_ip.sh
#
curl http://169.254.169.254/latest/meta-data/public-ipv4
echo
curl http://169.254.169.254/latest/meta-data/public-hostname
echo
#

B) Python3

get_ip.py
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#
#   get_ip.py
#
#                       Jan/09/2019
# ------------------------------------------------------------------
import sys
import requests
# ------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")

url="http://169.254.169.254/latest/meta-data/public-ipv4"
args={}

rr=requests.get(url,args)
print(rr.text)
#
url="http://169.254.169.254/latest/meta-data/public-hostname"
rr=requests.get(url,args)
print(rr.text)
#
sys.stderr.write("*** 終了 ***\n")
# ------------------------------------------------------------------

参考情報
インスタンスメタデータの取得

2
0
1

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
0