Skip to content

Instantly share code, notes, and snippets.

@dgulinobw
Created February 19, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgulinobw/19c965dbe333776caaf2c7d1c2cba041 to your computer and use it in GitHub Desktop.
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.
#!/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))
@amgill
Copy link

amgill commented Apr 11, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment