IP Address Validation

  • + 0 comments

    Real world solution (avoid doing such things manually):

    from ipaddress import ip_address
    
    for _ in range(int(input())):
        try:
            addr = ip_address(input())
            print("IPv4" if addr.version == 4 else "IPv6")
        except ValueError:
            print("Neither")