Files
Anthias/utils.py
Zachary Jones f0f67356d2 Make node IP introspection more robust. Should solve #49
Try multiple network interfaces when determining the node's IP address. Also, show correct port according to the settings.listen_port value. Previously was hardcoded to 8080, which may not be true if you've customized your port.
2013-02-08 18:16:27 -06:00

17 lines
369 B
Python

from netifaces import ifaddresses
def get_node_ip():
"""Returns this node's IP, if it can be
determined, returning None if not."""
precedence = ["eth0", "eth1", "en0", "en1"]
for interface in precedence:
try:
my_ip = ifaddresses(interface)[2][0]['addr']
return my_ip
except:
pass
return None