Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I m using Python AWS-SDK BOTO. I m trying to retrieve 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 the ipRange it shows nothing just two enter. When i check the type it is unicode. I even tried to conver to string str() but in vain.

What is the issue ? How can i retrieve the details ?

Please advice me.

like image 555
naga4ce Avatar asked Dec 30 '13 08:12

naga4ce


1 Answers

To loop over all security groups and print its rules including protocol, ports and ip range, try this:

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:

default
tcp 22 22 [0.0.0.0/0]
tcp 80 80 [0.0.0.0/0]
like image 185
andpei Avatar answered Sep 29 '22 08:09

andpei