Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_webhost(cherryhost, cherryport, https_port):
- """ Determine the webhost address and port,
- return (host, port, browserhost)
- """
- if cherryhost is None:
- cherryhost = sabnzbd.cfg.CHERRYHOST.get()
- else:
- sabnzbd.cfg.CHERRYHOST.set(cherryhost)
- # Get IP address, but discard APIPA/IPV6
- # If only APIPA's or IPV6 are found, fall back to localhost
- ipv4 = ipv6 = False
- localhost = hostip = 'localhost'
- try:
- info = socket.getaddrinfo(socket.gethostname(), None)
- except:
- # Hostname does not resolve, use 0.0.0.0
- cherryhost = '0.0.0.0'
- info = socket.getaddrinfo(localhost, None)
- for item in info:
- ip = item[4][0]
- if ip.startswith('169.254.'):
- pass # Is an APIPA
- elif ':' in ip:
- ipv6 = True
- elif '.' in ip and not ipv4:
- ipv4 = True
- hostip = ip
- # A blank host will use the local ip address
- if cherryhost == '':
- if ipv6 and ipv4:
- # To protect Firefox users, use numeric IP
- cherryhost = hostip
- browserhost = hostip
- else:
- cherryhost = socket.gethostname()
- browserhost = cherryhost
- # 0.0.0.0 will listen on all ipv4 interfaces (no ipv6 addresses)
- elif cherryhost == '0.0.0.0':
- # Just take the gamble for this
- cherryhost = '0.0.0.0'
- browserhost = localhost
- # :: will listen on all ipv6 interfaces (no ipv4 addresses)
- elif cherryhost in ('::','[::]'):
- cherryhost = cherryhost.strip('[').strip(']')
- # Assume '::1' == 'localhost'
- browserhost = localhost
- # IPV6 address
- elif '[' in cherryhost or ':' in cherryhost:
- browserhost = cherryhost
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement