Q:

How to find out if an IP address belong to a network with python2?

If we have a IP address like 192.168.1.168. And We have a network represented by 192.168.1.0/24
Is there a good way (least code) to find out if the ip belong to the network?
The model netaddr seems can, but did not figure out how.

A:

import netaddr

ip = netaddr.IPAddress('192.168.1.168')
network = netaddr.IPNetwork('192.168.1.0/24')

print ip in network

