I know there are some similar questions up here, but they mostly either want to find the range itself (which uses some libraries, like the example that stackoverflow says is
In Python 3.3 and later, you should be using the ipaddress module.
ipaddress
from ipaddress import ip_network, ip_address net = ip_network("1.1.0.0/16") print(ip_address("1.1.2.2") in net) # True