📜  验证 IP 地址 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:19.506000             🧑  作者: Mango

代码示例1
try:
            if len(IP.split('.')) == 4:
                print(IP)
                if all([bool(1) if(str(int(s)) == s and 0 <= int(s) <= 255) else bool(0) for s in IP.split('.')]):
                    return "IPv4"
            if len(IP.split(':')) == 8:
                if all([bool(1) if(len(s) <= 4 and int(s, 16) >= 0) else bool(0) for s in IP.split(':')]):
                    return "IPv6"
        except:
            return "Neither"
        return "Neither"