You can instead use netaddr:
import netaddr
try:
netaddr.IPAddress(input)
except AddrFormatError:
logging.error('Nope!')
else:
doSomethingWith(input)
You could also:
if netaddr.IPAddress('10.0.0.1') in netaddr.IPNetwork('10.0.0.0/8'):
logging.error('Yup!')
Assaf Muller, Cloud Networking Engineer
Red Hat
----- Original Message -----
From: "iKhan" <[email protected]>
To: "openstack-dev" <[email protected]>
Sent: Tuesday, January 21, 2014 4:55:05 AM
Subject: [openstack-dev] Validation of IP
Hi,
I am planning to validate an IP which is accepted part of input from user in
cinder, I need to verify if IP address is valid and it is up in the network.
The dirty way or only way that I know as of now is to create a socket object
and perform inet_aton() and gethostbyaddr()
Jut worried if these operations are safe to perform.
--
Thanks,
Ibad Khan
9686594607
_______________________________________________
OpenStack-dev mailing list
[email protected]
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
_______________________________________________
OpenStack-dev mailing list
[email protected]
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev