Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ifaddr>=0.1.0
jsonschema==2.6.*; python_version < '3.5'
jsonschema>=3.0.0; python_version >= '3.5'
netifaces>=0.10.0
pyee>=5.0.0
tornado==5.1.*; python_version < '3.5'
tornado>=6.0.0; python_version >= '3.5'
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
long_description = f.read()

requirements = [
'netifaces>=0.10.0',
'ifaddr>=0.1.0',
'pyee>=5.0.0',
]

Expand All @@ -39,7 +39,7 @@

setup(
name='webthing',
version='0.11.2',
version='0.11.3',
description='HTTP Web Thing implementation',
long_description=long_description,
url='https://github.com/mozilla-iot/webthing-python',
Expand Down
32 changes: 16 additions & 16 deletions webthing/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Utility functions."""

import datetime
import netifaces
import ifaddr
import socket


Expand Down Expand Up @@ -40,20 +40,20 @@ def get_addresses():
"""
addresses = set()

for iface in netifaces.interfaces():
for family, addrs in netifaces.ifaddresses(iface).items():
if family not in [netifaces.AF_INET, netifaces.AF_INET6]:
continue

# Sometimes, IPv6 addresses will have the interface name appended
# as, e.g. %eth0. Handle that.
for addr in [a['addr'].split('%')[0].lower() for a in addrs]:
# Filter out link-local addresses.
if family == netifaces.AF_INET and \
not addr.startswith('169.254.'):
addresses.add(addr)
elif family == netifaces.AF_INET6 and \
not addr.startswith('fe80:'):
addresses.add('[{}]'.format(addr))
for iface in ifaddr.get_adapters():
for addr in iface.ips:
# Filter out link-local addresses.
if addr.is_IPv4:
ip = addr.ip

if not ip.startswith('169.254.'):
addresses.add(ip)
elif addr.is_IPv6:
# Sometimes, IPv6 addresses will have the interface name
# appended, e.g. %eth0. Handle that.
ip = addr.ip[0].split('%')[0].lower()

if not ip.startswith('fe80:'):
addresses.add('[{}]'.format(ip))

return sorted(list(addresses))