def get_ip_address(iface):
"""Get IP address of the interface connected to the network.
If there is no such an interface, then localhost is returned.
"""
if iface not in netifaces.interfaces():
LOG.warning("Can't find interface '%s' in the host list of interfaces",
iface)
return '127.0.0.1'
address_family = netifaces.AF_INET
if address_family not in netifaces.ifaddresses(iface):
LOG.warning("Interface '%s' doesnt configured with ipv4 address",
iface)
return '127.0.0.1'
for ifaddress in netifaces.ifaddresses(iface)[address_family]:
if 'addr' in ifaddress:
return ifaddress['addr']
else:
LOG.warning("Can't find ip addr for interface '%s'", iface)
return '127.0.0.1'
评论列表
文章目录