import re


def _IPisvalid(ip):
    """检查 IP 地址是否合法"""
    pattern = re.compile(
        r"""^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} # ip 前三个断
        (?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$
        """,re.X
    )
    return bool(pattern.match(ip))