From 2e13186256d31b494025579ea5c2cfe8197c79c1 Mon Sep 17 00:00:00 2001 From: echel0n Date: Fri, 19 Dec 2014 22:58:01 -0800 Subject: [PATCH] Fixed sickragetv/sickrage-issues#205 - Getting a proper local lan ip --- sickbeard/helpers.py | 43 ++----------------------------------------- 1 file changed, 2 insertions(+), 41 deletions(-) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 6f5104fe..221df0f6 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -818,47 +818,8 @@ def md5_for_file(filename, block_size=2 ** 16): def get_lan_ip(): - """ - Simple function to get LAN localhost_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]) - - interfaces = [] - if ip.startswith("127."): - interfaces += [ - "eth0", - "eth1", - "eth2", - "wlan0", - "wlan1", - "wifi0", - "ath0", - "ath1", - "ppp0", - "rge0", - "rge1", - "rge2", - ] - - for ifname in interfaces: - try: - ip = get_interface_ip(ifname) - print ifname, ip - break - except IOError: - pass - - return ip - + try:return [ip for ip in socket.gethostbyname_ex(socket.gethostname())[2] if not ip.startswith("127.")][0] + except:return socket.gethostname() def check_url(url): """