Skip to content

Commit 8d2ffbb

Browse files
committed
utils.localinterfaces: Add PUBLIC_IPS to consolidate socket logic
Consolidating IP detection in this module will let us remove socket.gethostbyname_ex calls from other modules and ensure that everyone agrees on what our public IPs should be.
1 parent bb4531e commit 8d2ffbb

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

IPython/utils/localinterfaces.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
machine. It will *almost* always be '127.0.0.1'
66
77
LOCAL_IPS : A list of IP addresses, loopback first, that point to this machine.
8+
9+
PUBLIC_IPS : A list of public IP addresses that point to this machine.
10+
Use these to tell remote clients where to find you.
811
"""
912
#-----------------------------------------------------------------------------
1013
# Copyright (C) 2010-2011 The IPython Development Team
@@ -31,10 +34,14 @@
3134
except socket.gaierror:
3235
pass
3336

37+
PUBLIC_IPS = []
3438
try:
35-
LOCAL_IPS.extend(socket.gethostbyname_ex(socket.gethostname())[2])
39+
PUBLIC_IPS = socket.gethostbyname_ex(socket.gethostname())[2]
3640
except socket.gaierror:
3741
pass
42+
else:
43+
PUBLIC_IPS = uniq_stable(PUBLIC_IPS)
44+
LOCAL_IPS.extend(PUBLIC_IPS)
3845

3946
# include all-interface aliases: 0.0.0.0 and ''
4047
LOCAL_IPS.extend(['0.0.0.0', ''])

0 commit comments

Comments
 (0)