我想知道如何列出所有地区的aws的所有EIP或公共IP?
也许是通过aws cli或者python。
发布于 2020-03-11 16:14:52
我一直在等待,但没有人回答,因此,等了两分钟后,我将回答我自己的问题。
检查下面的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()谢谢你提前投票。
https://stackoverflow.com/questions/60640253
复制相似问题