Hello there,

>what am I going wrong here? i need to validate this is an IP or ask 
>the question again
>
>untrust_ip_address = raw_input('\nEnter the  untrust IP ''"Example 
>172.20.2.3/28"'':')

This is a representation of an IP address along with the mask length for the
prefix:

  172.20.2.3/28 

That is not, strictly speaking an IP, because there is ancillary 
information included.  This corresponds to:

  172.20.2.3     IP address
  172.20.2.0/28  prefix

The form you are showing is found on some systems, for example in 
the output from `ip address show` on Linux systems, but it is a 
commonly understood form.  Look further at the library that I 
recommended last week, and I think you will find a solution.

>while not ipaddress.ip_network untrust_ip_address:
>           untrust_ip_address = raw_input('\nEnter the  untrust IP ''"Example 
> 172.20.2.3/28"'':')

You might try using the ipaddress library in the following way:

  >>> i = ipaddress.ip_interface(u'172.20.2.3/28')
  >>> i.ip
  IPv4Address(u'172.20.2.3')
  >>> i.network
  IPv4Network(u'172.20.2.0/28')
  >>> i.with_prefixlen
  u'172.20.2.3/28'

Good luck,

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to