def check_rfc_1918(cidr):
 if (ipaddr.IPNetwork(cidr) in ipaddr.IPNetwork('10.0.0.0/8')):
  return True
 if (ipaddr.IPNetwork(cidr) in ipaddr.IPNetwork('172.16.0.0/12')):
  return True
 if (ipaddr.IPNetwork(cidr) in ipaddr.IPNetwork('192.168.0.0/16')):
  return True
 return False

def check_rfc_1918 ( cidr ) : if ( ipaddr . IPNetwork ( cidr ) in ipaddr . IPNetwork ( '10.0.0.0/8' ) ) : return True if ( ipaddr . IPNetwork ( cidr ) in ipaddr . IPNetwork ( '172.16.0.0/12' ) ) : return True if ( ipaddr . IPNetwork ( cidr ) in ipaddr . IPNetwork ( '192.168.0.0/16' ) ) : return True return False
ec2-classic sgs should never use rfc-1918 cidrs .