Skip to content

Instantly share code, notes, and snippets.

View guddu07's full-sized avatar

Prashant Tiwari guddu07

  • Australia
View GitHub Profile
@guddu07
guddu07 / find_internet_facing_sg.py
Created November 11, 2017 15:26
Boto3 supported script to list out all security groups from your account which are internet facing.
#!/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']:
import boto3
import subprocess
import re
def lambda_handler(event, context):
elb = boto3.client('elb')
buk = boto3.resource('s3')
elbs = elb.describe_load_balancers() # Getting all load balancers
f1 = open('/tmp/elbs.html', 'w') # Making file empty for reuse
f1.close()
with open('/tmp/elbs.html', 'ab') as f:
@guddu07
guddu07 / Find unused security groups using Boto3 in your AWS account
Last active April 12, 2022 15:01
Find unused security groups using Boto3 in your AWS account
import boto3 #Calling Boto3 library
ec2 = boto3.resource('ec2', region_name='us-west-2')
sgs = ec2.security_groups.all() # Fetching all security groups in AWS account
all_sgs = set([sg.group_name for sg in sgs]) # Creating a list of only security group names
instances = ec2.instances.all() # Getting all instances in AWS account