This script will list all instances, their security groups and all their rules.

Script can be downloaded from Cloudhowto official Github repository