1
# This Source Code Form is subject to the terms of the Mozilla Public
2
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
3
# You can obtain one at http://mozilla.org/MPL/2.0/.
11
def _get_interface_ip(ifname):
12
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
13
return socket.inet_ntoa(fcntl.ioctl(
16
struct.pack('256s', ifname[:15])
21
ip = socket.gethostbyname(socket.gethostname())
22
except socket.gaierror: # for Mac OS X
23
ip = socket.gethostbyname(socket.gethostname() + ".local")
25
if ip.startswith("127.") and os.name != "nt":
26
interfaces = ["eth0", "eth1", "eth2", "wlan0", "wlan1", "wifi0", "ath0", "ath1", "ppp0"]
27
for ifname in interfaces:
29
ip = _get_interface_ip(ifname)