#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 验证IP地址
# @param IP string字符串 一个IP地址字符串
# @return string字符串
#
import re
class Solution:
    def solve(self , IP: str) -> str:
        # write code here
        if self.is_v4(IP):
            return 'IPv4'
        if self.is_v6(IP):
            return 'IPv6'
        return 'Neither'
    
    @staticmethod
    def is_v4(ip):
        cells = ip.split('.')
        if cells.__len__() != 4: return False
        for cell in cells:
            try: 
                if 0>int(cell) or int(cell) > 255:
                    return False
            except: return False
            if re.findall(r'^\s*0[\d]?', cell): return False
        return True
    
    @staticmethod
    def is_v6(ip):
        cells = ip.split(':')
        if cells.__len__() != 8: return False
        for cell in cells:
            if not re.findall(r'^[0-9a-fA-F]{1,4}$', cell):
                return False
        return True