Created
February 19, 2018 22:48
-
-
Save dgulinobw/19c965dbe333776caaf2c7d1c2cba041 to your computer and use it in GitHub Desktop.
Print out ec2 security group inbound rules, so you can grep on IPs, etc.
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/env python | |
from __future__ import print_function | |
import json | |
import boto3 | |
for region in ["us-east-1","us-west-1", "us-west-2"]: | |
ec2=boto3.client('ec2', region ) | |
sgs = ec2.describe_security_groups()["SecurityGroups"] | |
for sg in sgs: | |
group_name = sg['GroupName'] | |
inbound = sg['IpPermissionsEgress'] | |
print("%s,%s: %s" % (region, group_name, inbound)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For "inbound" permissions, it should look like this (without "Egress"):
outbound = sg['IpPermissionsEgress']
inbound = sg['IpPermissions']
I have created an enhanced version that generates a csv file with all the rules. You can open it in Excel or Numbers to view security group rule just like they are displayed in AWS Web Console.
Generate AWS Security Groups Rules Report (CSV) of all the Security Groups