Created
November 11, 2017 15:26
-
-
Save guddu07/61037042dcca7e2e1fece7cba23e55c5 to your computer and use it in GitHub Desktop.
Boto3 supported script to list out all security groups from your account which are internet facing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import boto3 | |
ec2 = boto3.resource('ec2', region_name='ap-southeast-2') | |
sgs = ec2.security_groups.all() | |
security_groups = [sg.id for sg in sgs] | |
for security_group in security_groups: | |
sg = ec2.SecurityGroup(security_group) | |
for i in range(len(sg.ip_permissions)): | |
for j in range(len(sg.ip_permissions[i]['IpRanges'])): | |
if "0.0.0.0/0" in sg.ip_permissions[i]['IpRanges'][j]['CidrIp']: | |
print(sg.group_name, sg.ip_permissions[i]['ToPort'], sg.ip_permissions[i]['IpRanges'][j]['CidrIp']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment