本文介绍了如何判断我的AWS账户是否“拥有"了Python boto中的给定IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个公用IP地址列表,我想看看它们是否是与我们的帐户相关联的公用IP.我知道我可以简单地将每个IP粘贴到AWS EC2控制台的搜索框中.但是,我想通过Python程序自动执行此过程.

So I have a list of public IP addresses and I'd like to see if they are a public IP that is associated with our account. I know that I can simply paste each IP into the search box in the AWS EC2 console. However I would like to automate this process via a Python program.

有人告诉您您可以在控制台中执行的任何操作,可以通过CLI/程序执行,但是我使用哪个函数根据与我们的帐户相关联的公共IP来简单地返回结果或不返回结果?

I'm told anything you can do in the console, you can do via CLI/program, but which function do I use to simply either return a result or not, based on whether it's a public IP that's associated with our account?

我知道我可能必须进行两次搜索,其中一个实例(将涵盖非EIP公用IP),另一个EIP(将涵盖我们仍然拥有的分离EIP).

I understand I may have to do two searches, one of instances (which would cover non-EIP public IPs) and one of EIPs (which would cover disassociated EIPs that we still have).

但是如何?

推荐答案

使用boto,您需要做的第一件事就是致电 connect_to_region 以便连接到您感兴趣的AWS区域.(如果您有多个区域中的实例,则需要遍历每个区域一).

Using boto, the first thing you'll need to do is call connect_to_region in order to connect to the AWS region you're interested in. (If you have instances in multiple regions then you'll need to iterate over each region one by one).

连接到某个区域后,您需要致电 get_only_instances ,它将返回实例对象的列表.浏览这些对象的列表,然后查看实例公共IP的ip_address字段(或私有IP的private_ip_address字段).

Once you've connected to a region you'll need to call get_only_instances which will return a list of instance objects. Go through the list of those objects and look at the ip_address field for the instances public IP (or the private_ip_address field for the private one).

然后,您将要致电 get_all_addresses 以获得弹性IP的列表.再一次,您将需要遍历EIP对象的列表,并在这种情况下查看public_ip字段.而且,如果您想确定EIP与哪个实例相关联(如果有),那么instance_id字段将执行此操作.

Then you'll want to call get_all_addresses to get a list of Elastic IP's. Once again you'll need to loop through the list of EIP objects and look at the public_ip field in this case. And if you want to determine which instance the EIP is associated with (if any) then the instance_id field will do that.

这篇关于如何判断我的AWS账户是否“拥有"了Python boto中的给定IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 07:14