Last active
November 19, 2015 22:03
-
-
Save Jonarzz/f9cc3e855ee673317bf3 to your computer and use it in GitHub Desktop.
The script takes N as number of lines to read; then takes N lines and checks if the line is IPv4, IPv6 or neither.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
n = int(input()) | |
for _ in range(n): | |
output = 'Neither' | |
line = str(input()) | |
match = re.match(r'^(\d{0,3})\.(\d{0,3})\.(\d{0,3})\.(\d{0,3})$', line) | |
if match is not None: | |
groups = match.groups() | |
output = 'IPv4' | |
for group in groups: | |
if int(group) > 255: | |
output = 'Neither' | |
break | |
else: | |
match = re.search(r'^([0-9a-f]{0,4}:){7}[0-9a-f]{0,4}$', line) | |
if match is not None: | |
output = 'IPv6' | |
else: | |
output = 'Neither' | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment