Quick actions

cmd+k|ctrl+k

Navigation

Languages

Does IP belong to the network

Snippet info

Language

Python

Visibility

public

Author

homam

Created

2024-03-28T09:06:30.849895Z

Updated

2024-03-28T09:06:30.849895Z

from ipaddress import ip_network, ip_address

# Define the CIDR block
cidr = ip_network('188.88.0.0/19')

# List of IP addresses to check
ips = [
    '188.88.2.98',
    '188.81.255.254',
    '188.88.12.171',
    '188.88.191.2'
]

# Check which IP does not belong to the CIDR
not_in_cidr = [ip for ip in ips if ip_address(ip) not in cidr]
print(not_in_cidr)
INFO