mirror of
https://github.com/moparisthebest/SickRage
synced 2024-11-15 13:55:05 -05:00
Updated code for get_lan_ip to fix issues with returning local lan ip from network interface.
This commit is contained in:
parent
4e0a4c3f99
commit
8e9f4f47cb
@ -823,28 +823,32 @@ def get_lan_ip():
|
|||||||
http://stackoverflow.com/questions/11735821/python-get-localhost-ip
|
http://stackoverflow.com/questions/11735821/python-get-localhost-ip
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
ip = socket.gethostbyname(socket.gethostname())
|
||||||
if os.name != "nt":
|
if os.name != "nt":
|
||||||
import fcntl
|
import fcntl
|
||||||
import struct
|
import struct
|
||||||
|
|
||||||
def get_interface_ip(ifname):
|
def get_interface_ip(ifname):
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s',
|
return socket.inet_ntoa(fcntl.ioctl(s.fileno(), 0x8915, struct.pack('256s', ifname[:15]))[20:24])
|
||||||
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:
|
for ifname in interfaces:
|
||||||
try:
|
try:
|
||||||
ip = get_interface_ip(ifname)
|
ip = get_interface_ip(ifname)
|
||||||
@ -852,6 +856,7 @@ def get_lan_ip():
|
|||||||
break
|
break
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return ip
|
return ip
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user