From cabef5785197a0b83c2a6697e4b9afcdea132cc8 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sun, 5 May 2013 10:13:26 -0500 Subject: [PATCH] improved ipv6 address checked, thanks Jonathan --- VERSION | 2 +- gluon/main.py | 4 ++-- gluon/utils.py | 12 +++++------- gluon/widget.py | 6 +++--- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/VERSION b/VERSION index fe40e0e2..16e759a9 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.4.6-stable+timestamp.2013.05.04.10.23.42 +Version 2.4.6-stable+timestamp.2013.05.05.10.12.31 diff --git a/gluon/main.py b/gluon/main.py index 81169857..7e861cc2 100644 --- a/gluon/main.py +++ b/gluon/main.py @@ -471,11 +471,11 @@ def wsgibase(environ, responder): local_hosts.add(socket.gethostname()) local_hosts.add(fqdn) local_hosts.update([ - ip[4][0] for ip in getipaddrinfo(fqdn)]) + addrinfo[4][0] for addrinfo in getipaddrinfo(fqdn)]) if env.server_name: local_hosts.add(env.server_name) local_hosts.update([ - ip[4][0] for ip in getipaddrinfo(env.server_name)]) + addrinfo[4][0] for addrinfo in getipaddrinfo(env.server_name)]) except (socket.gaierror, TypeError): pass global_settings.local_hosts = list(local_hosts) diff --git a/gluon/utils.py b/gluon/utils.py index 1051b8c1..733c6f3a 100644 --- a/gluon/utils.py +++ b/gluon/utils.py @@ -298,18 +298,16 @@ def is_valid_ip_address(address): def is_loopback_ip_address(ip=None, addrinfo=None): """ Determines whether the address appears to be a loopback address. - - This assumes that the IP is valid. The IPv6 check is limited to '::1'. - + This assumes that the IP is valid. """ if addrinfo: # see socket.getaddrinfo() for layout of addrinfo tuple if addrinfo[0] == socket.AF_INET or addrinfo[0] == socket.AF_INET6: ip = addrinfo[4] - if not ip: + if not isinstance(ip, basestring): return False - if isinstance(ip, basestring) and ip.count('.') == 3: # IPv4 - return ip.startswith('127') or ip.startswith('::ffff:127') - return ip == '::1' # IPv6 + if ip.count('.') == 3: # IPv4 + return ip.startswith('127') or ip.startswith('::127') or ip.startswith(' 0:0:0:0:0:0:127') + return ip == '::1' or ip == '0:0:0:0:0:0:0:1' # IPv6 loopback def getipaddrinfo(host): diff --git a/gluon/widget.py b/gluon/widget.py index a6cf6ed1..faffc653 100644 --- a/gluon/widget.py +++ b/gluon/widget.py @@ -939,9 +939,9 @@ def console(): global_settings.cmd_args = args try: - options.ips = list(set([ - addrinfo[4][0] for addrinfo in getipaddrinfo(socket.getfqdn()) - if not is_loopback_ip_address(addrinfo=addrinfo)])) + options.ips = list(set( # no duplicates + [addrinfo[4][0] for addrinfo in getipaddrinfo(socket.getfqdn()) + if not is_loopback_ip_address(addrinfo=addrinfo)])) except socket.gaierror: options.ips = []