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
For python 2 & 3 use:
python 2 & 3
from ipaddress import ip_network, ip_address def in_cidr(ip, cidr): return ip_address(ip) in ip_network(cidr)
Demo
For pyhton 2.7 install using:
pyhton 2.7
pip install ipaddress