|
|
|
|
|
by MichaelSalib
4639 days ago
|
|
Maybe something like this: def is_ipv4_addr(s):
try:
octets = s.split('.')
assert len(octets) == 4
for o in octets:
assert 0 <= int(o.lstrip(0) or '0') < 256
except:
return False
return True
It is longer; on the other hand, it is easier to read and more importantly easier to verify correctness. |
|