[openstack-dev] Validation of IP

Assaf Muller amuller at redhat.com
Tue Jan 21 07:56:34 UTC 2014


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" <ik.ibadkhan at gmail.com>
To: "openstack-dev" <openstack-dev at lists.openstack.org>
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
OpenStack-dev at lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev



More information about the OpenStack-dev mailing list