import ipaddress
MY_VPC_SUBNETS = [“10.0.0.0/8”, “172.16.0.0/12”, “192.168.0.0/16”]
MY_SG_IPS = [“10.16.0.0/12”, “172.16.12.0/28”, “10.15.90.2/32”, “60.20.15.0/24”]
for network in MY_VPC_SUBNETS:
invalid_ips =
internal_network = ipaddress.ip_network(network)
for my_valid_ip in MY_SG_IPS:
my_ip = ipaddress.ip_network(my_valid_ip)
if not my_ip.subnet_of(internal_network):
print(my_ip, “in subnet”, internal_network)
So, I’m having some hard time finding the logic to finally tell me
“ip 60.x.x.x/y is not part of MY_VPC_SUBNETS”
Help for a Python Newbie pls !