import ipaddress
import logging


def _get_ip_block(ip_block_str):
    """ Convert string into ipaddress.ip_network. Support both IPv4 or IPv6
    addresses.

        Args:
            ip_block_str(string): network address, e.g. "192.168.0.0/24".

        Returns:
            ip_block(ipaddress.ip_network)
    """
    try:
        ip_block = ipaddress.ip_network(ip_block_str)
    except ValueError:
        logging.error("Invalid IP block format: %s", ip_block_str)
        return None
    return ip_block