#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
# 验证IP地址
# @param IP string字符串 一个IP地址字符串
# @return string字符串
#
import re
class Solution:
def solve(self , IP: str) -> str:
# write code here
ip=IP.split('.')
ipv6s=IP.split(':')
if len(ip) == 4:
for ip1 in ip:
if not ip1.isdigit():
return 'Neither'
elif int(ip1[0]) == 0:
return 'Neither'
elif int(ip1)<256:
continue
else:
return 'Neither'
return 'IPv4'
elif len(ipv6s) == 8:
for ipv6 in ipv6s:
if ipv6 == '':
return 'Neither'
elif len(ipv6) >4:
return 'Neither'
elif ipv6.isdigit() and len(ipv6) >1 and int(ipv6) == 0:
return 'Neither'
if not re.match(r'^[0-9a-fA-F]{1,4}$', ipv6):
return 'Neither'
else:
continue
return 'IPv6'
else:
return 'Neither'