Re: [Tutor] Validating String contains IP address

2017-04-04 Thread Ed Manning
Thank you very much Sent from my iPhone > On Apr 3, 2017, at 7:04 PM, Martin A. Brown wrote: > > > 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

Re: [Tutor] Validating String contains IP address

2017-04-03 Thread Alan Gauld via Tutor
On 03/04/17 19:43, Ed Manning wrote: > untrust_ip_address = raw_input('\nEnter the untrust IP ''"Example > 172.20.2.3/28"'':') > while not ipaddress.ip_network untrust_ip_address: Doesn't that give a syntax error? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http

Re: [Tutor] Validating String contains IP address

2017-04-03 Thread Martin A. Brown
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

Re: [Tutor] Validating String contains IP address

2017-04-03 Thread Ed Manning
Hello 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"'':') while not ipaddress.ip_network untrust_ip_address: untrust_ip_address = raw_input('\nEnter the untrus

Re: [Tutor] Validating String contains IP address

2017-04-01 Thread Alan Gauld via Tutor
On 01/04/17 17:29, Alex Kleider wrote: > Good point! I hadn't considered IPV6 and didn't know about the ipaddress > module. Me too, on both counts. Actually I should have known about ipaddress because this question has come up before but I'd forgotten... :-( And as for forgetting IP6 - as an ex

Re: [Tutor] Validating String contains IP address

2017-04-01 Thread Alex Kleider
On 2017-03-31 18:01, Mats Wichmann wrote: On 03/31/2017 06:44 PM, Alex Kleider wrote: On 2017-03-31 16:35, Ed Manning wrote: What's the best way to validate a string contains a IP address Sent from my iPad ___ Tutor maillist - Tutor@python.org To un

Re: [Tutor] Validating String contains IP address

2017-04-01 Thread Mats Wichmann
On 03/31/2017 06:44 PM, Alex Kleider wrote: > On 2017-03-31 16:35, Ed Manning wrote: >> What's the best way to validate a string contains a IP address >> Sent from my iPad >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscript

Re: [Tutor] Validating String contains IP address

2017-03-31 Thread Steven D'Aprano
On Fri, Mar 31, 2017 at 07:35:48PM -0400, Ed Manning wrote: > > What's the best way to validate a string contains a IP address Don't reinvent the wheel, use the ipaddress module. py> import ipaddress py> ipaddress.ip_address('99.99.99.99') IPv4Address('99.99.99.99') If the address is not a va

Re: [Tutor] Validating String contains IP address

2017-03-31 Thread Alex Kleider
On 2017-03-31 16:35, Ed Manning wrote: What's the best way to validate a string contains a IP address Sent from my iPad ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] Validating String contains IP address

2017-03-31 Thread Martin A. Brown
Hello there, >What's the best way to validate a string contains a IP address If you are only talking about validating that something is an IP address, then I can even give you a little Python2 / Python3 snippet that can do that. I like the EAFP [0] approach for this sort of thing. There ar

Re: [Tutor] Validating String contains IP address

2017-03-31 Thread Alan Gauld via Tutor
On 01/04/17 00:35, Ed Manning wrote: > > What's the best way to validate a string contains a IP address It depends on how thorough you want to be. You can define a regex to check that its 4 groups of numbers separated by periods. Or you can split the string into fields and validate that the val