mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-19 12:59:42 -07:00
Update IP helper function
This commit is contained in:
parent
7245e97726
commit
efdd4156d8
1 changed files with 7 additions and 5 deletions
|
@ -1194,18 +1194,20 @@ def get_plexpy_url(hostname=None):
|
||||||
scheme = 'http'
|
scheme = 'http'
|
||||||
|
|
||||||
if hostname is None and plexpy.CONFIG.HTTP_HOST in ('0.0.0.0', '::'):
|
if hostname is None and plexpy.CONFIG.HTTP_HOST in ('0.0.0.0', '::'):
|
||||||
import socket
|
# Only returns IPv4 address
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||||
|
s.settimeout(0)
|
||||||
try:
|
try:
|
||||||
# Only returns IPv4 address
|
s.connect(('<broadcast>', 1))
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
||||||
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
|
||||||
s.connect(('<broadcast>', 0))
|
|
||||||
hostname = s.getsockname()[0]
|
hostname = s.getsockname()[0]
|
||||||
except socket.error:
|
except socket.error:
|
||||||
try:
|
try:
|
||||||
hostname = socket.gethostbyname(socket.gethostname())
|
hostname = socket.gethostbyname(socket.gethostname())
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
pass
|
pass
|
||||||
|
finally:
|
||||||
|
s.close()
|
||||||
|
|
||||||
if not hostname:
|
if not hostname:
|
||||||
hostname = 'localhost'
|
hostname = 'localhost'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue