使用Python脚本抓取aws所有的IP地址

为了满足客户业务需求,需要抓取AWS新加坡所有IP地址来设定路由。AWS官网有专门的链接列出所有IP地址,所以只需要利用脚本筛选出新加坡地址就OK。

所有IP地址链接:https://ip-ranges.amazonaws.com/ip-ranges.json

上述链接中“region”分别代表的意思:区域和可用区 - Amazon Elastic Compute Cloud

aws官网给出的抓取方法:AWS IP 地址范围 - AWS 一般参考

[root@PythonLearn home]# cat get_ips.py 
#!/usr/bin/env python
import requests

ip_ranges = requests.get('https://ip-ranges.amazonaws.com/ip-ranges.json').json()['prefixes']
amazon_ips = [item['ip_prefix'] for item in ip_ranges if item["region"] == "ap-southeast-1"]
ec2_ips = [item['ip_prefix'] for item in ip_ranges if item["service"] == "EC2"]


for ip in amazon_ips: print(str(ip))

区域选择: ap-southeast-1  (新加坡)

类型选择:ip_prefix   (只抓取ipv4)

[root@PythonLearn home]# ./get_ips.py 
52.95.212.0/22
52.93.8.0/22
103.246.148.0/23
52.219.132.0/22
52.92.56.0/22
52.93.19.236/32
15.221.8.0/21
54.240.199.0/24
54.240.227.0/24
52.93.19.237/32
52.95.35.0/24
52.144.231.64/26
99.82.173.0/24
52.94.11.0/24
52.219.40.0/22
52.219.32.0/21
52.219.48.0/22
150.222.78.0/24
13.248.107.0/24
52.94.198.96/28
52.219.124.0/22
52.219.128.0/22
150.222.108.0/24
54.240.226.0/24
52.119.184.0/22
43.250.193.0/24
43.250.192.0/24
52.144.224.128/26
54.239.0.96/28
52.93.63.0/24
203.83.220.0/22
54.255.254.192/26
54.251.31.128/26
52.219.132.0/22
52.92.56.0/22
52.219.40.0/22
52.219.32.0/21
52.219.48.0/22
52.219.124.0/22
52.219.128.0/22
52.94.11.0/24
13.228.69.0/24
52.220.191.0/26
52.221.221.128/29
99.82.173.0/24
13.248.107.0/24
13.251.113.64/26
13.251.116.0/23
18.138.134.128/25
18.138.244.0/23
13.250.186.128/27
13.250.186.160/27
3.0.5.32/29
52.76.127.0/24

IP地址会更新,所以脚本可以设置定期运行。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值