用于Python Boto3的AWS开发工具包未描述重复的端口号安全规则。此外,未描述安全组规则,这些规则未在输出中列出。
这是我的代码
#!/ usr / bin / python3.6
导入boto3
session = boto3.session.Session(profile_name =“ Karan”)
ec2security = session.client('ec2',region_name =“ ap-south-1”)
response_sg = ec2security.describe_security_groups()[“ SecurityGroups”]
对于response_sg中的sg:
group_name = sg [“ GroupName”]
group_desc = sg [“描述”]
打印(group_name,group_desc)
group_IPpermission = sg [“ IpPermissions”]
对于组IP权限中的in_rules:
如果in_rules ['IpProtocol'] ==“ -1”:
traffic_type =“所有点击量”
ip_protocol =“全部”
print(traffic_type,ip_protocol,end =“”)
其他:
from_port = in_rules ['FromPort']
ip_protocol = in_rules ['IpProtocol']
print(from_port,ip_protocol,end =“”)
ip_range = in_rules ['IpRanges']
对于ip_range中的iprange:
cidr = ipranges ['CidrIp']
cidr_desc = ipranges ['说明']
print(cidr,cidr_desc)