BOTO: How to get ipRanges from a security group object?

I am using Python AWS-SDK BOTO . I am trying to get all the security group details of my account.

secgrpList = ec2conn.get_all_security_groups()
ipRange = secgrpList[0].rules[1].ipRanges
print ipRange
print type(ipRange).__name__

But when I print ipRange, it shows only two enter. When I check the type, it is unicode. I even tried converting the str () string , but to no avail.

What is the problem? How can I get the details?

Please advise me.

+4
source share
3 answers

To iterate over all security groups and print your rules, including protocol, ports and ip range, try the following:

import boto.ec2
conn = boto.ec2.connect_to_region("eu-west-1")
groups = conn.get_all_security_groups()
for group in groups:
    print group.name
    for rule in group.rules:
        print rule.ip_protocol, rule.from_port, rule.to_port, rule.grants

which may result in:

default
tcp 22 22 [0.0.0.0/0]
tcp 80 80 [0.0.0.0/0]
+12

AWS CLI.

aws ec2 describe-security-groups --query 'SecurityGroups[*].IpPermissions[*].IpRanges' --output text

, : http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html

+2

but this is not an enumeration of the rules that have an IPv6 address.

0
source

All Articles