Hi,
I would probably take the string, separate the numbers and check they
are acceptable:
def correct_ip(ip):
# Check if my IP address has 4 numbers separated by dots
num=ip.split('.')
if not len(num)==4:
return False
# Check each of the 4 numbers is between 0 and 255
for n in num:
try:
if int(n) < 0 or int(n) > 255:
return False
except:
return False
return True
You could also go the regexp way, but I find it a bit more complicated.
Hope it helps,
G
On 11/3/06, Asrarahmed Kadri <[EMAIL PROTECTED]> wrote:
>
> Hi Folks,
>
> I want to implement a simple program that verifies the IP provided by the
> user is in the right format or not.
>
> How to go about it..?
> Any suggestions..
>
> TIA.
> Regards,
> Asrarahmed
>
>
> --
> To HIM you shall return.
> _______________________________________________
> Tutor maillist - [email protected]
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor