Show More
@@ -0,0 +1,40 b'' | |||
|
1 | """Simple utility for building a list of local IPs using the socket module. | |
|
2 | This module defines two constants: | |
|
3 | ||
|
4 | LOCALHOST : The loopback interface, or the first interface that points to this | |
|
5 | machine. It will *almost* always be '127.0.0.1' | |
|
6 | ||
|
7 | LOCAL_IPS : A list of IP addresses, loopback first, that point to this machine. | |
|
8 | """ | |
|
9 | #----------------------------------------------------------------------------- | |
|
10 | # Copyright (C) 2010 The IPython Development Team | |
|
11 | # | |
|
12 | # Distributed under the terms of the BSD License. The full license is in | |
|
13 | # the file COPYING, distributed as part of this software. | |
|
14 | #----------------------------------------------------------------------------- | |
|
15 | ||
|
16 | #----------------------------------------------------------------------------- | |
|
17 | # Imports | |
|
18 | #----------------------------------------------------------------------------- | |
|
19 | ||
|
20 | import socket | |
|
21 | ||
|
22 | #----------------------------------------------------------------------------- | |
|
23 | # Code | |
|
24 | #----------------------------------------------------------------------------- | |
|
25 | ||
|
26 | LOCAL_IPS = [] | |
|
27 | try: | |
|
28 | LOCAL_IPS = socket.gethostbyname_ex('localhost')[2] | |
|
29 | except socket.gaierror: | |
|
30 | pass | |
|
31 | ||
|
32 | try: | |
|
33 | LOCAL_IPS.extend(socket.gethostbyname_ex(socket.gethostname())[2]) | |
|
34 | except socket.gaierror: | |
|
35 | pass | |
|
36 | ||
|
37 | # include all-interface aliases: 0.0.0.0 and '' | |
|
38 | LOCAL_IPS.extend(['0.0.0.0', '']) | |
|
39 | ||
|
40 | LOCALHOST = LOCAL_IPS[0] |
General Comments 0
You need to be logged in to leave comments.
Login now