improved ipv6 address checked, thanks Jonathan
This commit is contained in:
committed by
Tim Richardson
parent
98ad12a06c
commit
cabef57851
@@ -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
|
||||||
|
|||||||
+2
-2
@@ -471,11 +471,11 @@ def wsgibase(environ, responder):
|
|||||||
local_hosts.add(socket.gethostname())
|
local_hosts.add(socket.gethostname())
|
||||||
local_hosts.add(fqdn)
|
local_hosts.add(fqdn)
|
||||||
local_hosts.update([
|
local_hosts.update([
|
||||||
ip[4][0] for ip in getipaddrinfo(fqdn)])
|
addrinfo[4][0] for addrinfo in getipaddrinfo(fqdn)])
|
||||||
if env.server_name:
|
if env.server_name:
|
||||||
local_hosts.add(env.server_name)
|
local_hosts.add(env.server_name)
|
||||||
local_hosts.update([
|
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):
|
except (socket.gaierror, TypeError):
|
||||||
pass
|
pass
|
||||||
global_settings.local_hosts = list(local_hosts)
|
global_settings.local_hosts = list(local_hosts)
|
||||||
|
|||||||
+5
-7
@@ -298,18 +298,16 @@ def is_valid_ip_address(address):
|
|||||||
def is_loopback_ip_address(ip=None, addrinfo=None):
|
def is_loopback_ip_address(ip=None, addrinfo=None):
|
||||||
"""
|
"""
|
||||||
Determines whether the address appears to be a loopback address.
|
Determines whether the address appears to be a loopback address.
|
||||||
|
This assumes that the IP is valid.
|
||||||
This assumes that the IP is valid. The IPv6 check is limited to '::1'.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if addrinfo: # see socket.getaddrinfo() for layout of addrinfo tuple
|
if addrinfo: # see socket.getaddrinfo() for layout of addrinfo tuple
|
||||||
if addrinfo[0] == socket.AF_INET or addrinfo[0] == socket.AF_INET6:
|
if addrinfo[0] == socket.AF_INET or addrinfo[0] == socket.AF_INET6:
|
||||||
ip = addrinfo[4]
|
ip = addrinfo[4]
|
||||||
if not ip:
|
if not isinstance(ip, basestring):
|
||||||
return False
|
return False
|
||||||
if isinstance(ip, basestring) and ip.count('.') == 3: # IPv4
|
if ip.count('.') == 3: # IPv4
|
||||||
return ip.startswith('127') or ip.startswith('::ffff:127')
|
return ip.startswith('127') or ip.startswith('::127') or ip.startswith(' 0:0:0:0:0:0:127')
|
||||||
return ip == '::1' # IPv6
|
return ip == '::1' or ip == '0:0:0:0:0:0:0:1' # IPv6 loopback
|
||||||
|
|
||||||
|
|
||||||
def getipaddrinfo(host):
|
def getipaddrinfo(host):
|
||||||
|
|||||||
+3
-3
@@ -939,9 +939,9 @@ def console():
|
|||||||
global_settings.cmd_args = args
|
global_settings.cmd_args = args
|
||||||
|
|
||||||
try:
|
try:
|
||||||
options.ips = list(set([
|
options.ips = list(set( # no duplicates
|
||||||
addrinfo[4][0] for addrinfo in getipaddrinfo(socket.getfqdn())
|
[addrinfo[4][0] for addrinfo in getipaddrinfo(socket.getfqdn())
|
||||||
if not is_loopback_ip_address(addrinfo=addrinfo)]))
|
if not is_loopback_ip_address(addrinfo=addrinfo)]))
|
||||||
except socket.gaierror:
|
except socket.gaierror:
|
||||||
options.ips = []
|
options.ips = []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user