Sunday 21 June 2020

How do I check if IP is whitelisted on Ec2 instance?

With many service groups and rules whitelisting access in the service group, it is often difficult to find out if specific IP is white listed or not. Or sometimes you need list of all the rules attached to a specific Ec2 instance.


ec2-whitelistcheck.py  : Is a Python boto3 script that will accept Instance ID as input and
        ec2 :  Print all the Rules attached to Instance
        ec2check : Check whether specified IP is whitelisted or not. Can accept multiple IP addresses.


Boto3 python script whitelist security group aws



Friday 12 June 2020

Python printing colourful text


Pythons scripts running on terminal can make use of Terminal colours to enhance output.



Using Combination of Foreground and Backgrunod can ensure required colours.
\033[1;41m \033[97m{} \033[00m"

The way I manage is by defining function and call with required text. Or you could define it in your own class and include

Text FormatForeground (text) colorBackground color
0: normal text30: Black40: Black
1: bold31: Red41: Red
4: Underlined text32: Green42: Green
33: Yellow43: Yellow
34: Blue44: Blue
35: Purple45: Purple
36: Cyan46: Cyan
37: White47: White



AWS Check IP Whitelisting

Python Boto3 script to print all SG rules attached to a LoadBalancer

  • How to list or check all the Security group rules attached to ELB/ALB
  • How to find out if specific IP is whitelisted or not


AWS Boto3 script will take Loadbalancer as argument and loop through all Security groups attached and print or check if IP provided are whitelisted or not.

Help is available by run -h at anypoint





  • Listing all Security Group rules attached to an ALB
   ./lb-whitelistcheck.py alb -l vettomalb1 -p vettomprofile -r eu-central-1
  INFO : Printing SG rules attached to ALB vettomalb1 using Profile=vettomprofile, Region=eu-central-1
  Procssing SG ['sg-00bb3ba21b32d6e', 'sg-07677a1dea9c6a']

 sg-003ba21b7832d6e  54.20.13.152/32  80 - 443
 sg-00bba21b7832d6e  54.28.231.43/32  80 - 443
 sg-00bb3bab7832d6e  56.208.110.37/32  80 - 443
 sg-07d7dd42ae859cd  192.150.3.2/32  22 - 443

  • Check if provided IP are whitelisted or not
./lb-whitelistcheck.py albcheck -l vettomalb1 -p vettomprofile -r eu-central-1 -s 192.147.118.254 192.168.3.2 10.50.0.0

192.147.118.254 allowed in SG=sg-07d7f2ae859cd Rule=192.147.118.254/32 Ports 22-443
192.168.3.2 not whitelisted.

10.50.0.0 allowed in SG=sg-0f9f542ae859cd Rule=10.50.0.0/24 Ports 22-22
aws boto3 whitelist check