python,求个关于ip合法性验证的方法

2025-05-18 09:30:48
推荐回答(1个)
回答1:

def IPChecker_re(istr):
    import re
    istr = istr.replace('.', '-')
    pattern = re.compile("(?:[0-255]-){3}[0-255]")
    if pattern.match(istr) is not None:
        return True
    return False