From 8e9f4f47cb1a3046f99ec0eaa6d2155d6f542765 Mon Sep 17 00:00:00 2001 From: echel0n Date: Fri, 19 Dec 2014 22:30:06 -0800 Subject: [PATCH] Updated code for get_lan_ip to fix issues with returning local lan ip from network interface. --- sickbeard/helpers.py | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index fce33426..6f5104fe 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -823,28 +823,32 @@ def get_lan_ip(): http://stackoverflow.com/questions/11735821/python-get-localhost-ip """ + ip = socket.gethostbyname(socket.gethostname()) if os.name != "nt": import fcntl import struct def get_interface_ip(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', - ifname[:15]))[20:24]) + return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24]) + + interfaces = [] + if ip.startswith("127."): + interfaces += [ + "eth0", + "eth1", + "eth2", + "wlan0", + "wlan1", + "wifi0", + "ath0", + "ath1", + "ppp0", + "rge0", + "rge1", + "rge2", + ] - ip = socket.gethostbyname(socket.gethostname()) - if ip.startswith("127.") and os.name != "nt": - interfaces = [ - "eth0", - "eth1", - "eth2", - "wlan0", - "wlan1", - "wifi0", - "ath0", - "ath1", - "ppp0", - ] for ifname in interfaces: try: ip = get_interface_ip(ifname) @@ -852,6 +856,7 @@ def get_lan_ip(): break except IOError: pass + return ip