Control if a input text is IP
Fredrik Lundh
fredrik at pythonware.com
Thu Feb 2 18:15:36 EST 2006
Sbaush wrote:
> My app has in input an ip address in IPv4 notation.
> is there a function that control if input is a string in IPv4 notation?
here's one way to do it:
def ipcheck(s):
try:
a, b, c, d = [chr(int(c)) for c in s.split(".")]
except ValueError:
return False
else:
return True
another way is to use regular expressions; see
http://www.regular-expressions.info/examples.html
</F>
More information about the Python-list
mailing list