[英]How to get list of all latest EIP of AWS for all regions
我想知道如何列出所有地區的aws的所有EIP或公共IP?
也許通過 aws cli 或 python。
我已經等了但沒有人回答,因此等了 2 分鍾后,我現在要回答我自己的問題。
檢查下面的python代碼,它會列出aws擁有的每個區域的EIP數量
import requests, ipaddress, boto3
client = boto3.client('ec2')
awsRegions = [region['RegionName'] for region in client.describe_regions()['Regions']]
resp = requests.get('https://ip-ranges.amazonaws.com/ip-ranges.json')
for eachRegion in awsRegions:
ip_pool = []
for prefix in resp.json()['prefixes']:
if prefix['region'] == eachRegion and prefix['service'] == 'EC2':
ip_pool.append(prefix['ip_prefix'])
total_ip = []
for eachCIDR in ip_pool:
net = ipaddress.ip_network(eachCIDR)
total_ip.append(int(net.num_addresses))
print (f'[{eachRegion}] total IP ==> {sum(total_ip)}')
exit()
提前感謝所有投票。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.