You are viewing a single comment's thread. Return to all comments →
Python 3 solution:
import re _octet = r'(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)' IPv4 = re.compile(rf'^{_octet}\.{_octet}\.{_octet}\.{_octet}$') IPv6 = re.compile(r'^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$') def classify(addr): if IPv4.fullmatch(addr): return "IPv4" if IPv6.fullmatch(addr): return "IPv6" return "Neither" N = int(input()) for _ in range(N): line = input() print(classify(line))
Seems like cookies are disabled on this browser, please enable them to open this website
IP Address Validation
You are viewing a single comment's thread. Return to all comments →
Python 3 solution: