import ipaddress
import logging


def validate_network_cidr(network_cidr):
    """
    validate ip address with cidr format. defaults to /24 if only IP is given

    """
    compressed_network_cidr = ''
    while True:
        try:
            compressed_network_cidr = ipaddress.ip_network(network_cidr)
            break
        except ValueError:
            logging.warn('input should be in format x.x.x.x/x')
            network_cidr = input('enter the network cidr: ')

    return compressed_network_cidr.compressed