suppose if you need to enumerate ip addresses from a list, but want to exclude ip addresses belonging to a subnet here’s a solution which you can do with netaddr module.
Supposed ip_from_inventory is the list of ip addresses you have obtained from a file.
from netaddr import IPNetwork, IPAddress for ip_item in ip_from_inventory: if IPAddress(ip_item) not in IPNetwork('192.168.1.0/24').iter_hosts(): print(ip_item)
This example exclude ip address that belongs to 192.168.1.0/24, and will list other ip addresses that are not.