re Challenge: More Compact?
Remco Gerlich
scarblac at pino.selwerd.nl
Mon Jul 16 06:49:10 EDT 2001
Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> wrote in comp.lang.python:
> Sun, 15 Jul 2001 21:36:22 -0400, Tim Peters <tim.one at home.com> pisze:
>
> > def valid_ip(ip):
> > m = re.match(r'(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$', ip)
> > if m:
> > elements = map(int, m.groups())
> > return max(elements) < 256
> > return 0
>
> Is 0127.0.0.00001 a valid IP?
>
> If yes, then it should be accepted. If no, what about 127.0.0.001?
Many POSIX inet_aton implementations interpret '0127' as an octal, but
that's nonstandard behavior. I don't think IP number syntax is defined very
well.
(from a quick scan of some rfcs, ie rfc 820 and rfc 2553).
--
Remco Gerlich
More information about the Python-list
mailing list