Skip to content

Commit

Permalink
SW-2070 find mr beam plugin to send network interfaces info to cloud …
Browse files Browse the repository at this point in the history
…- 2 #46

* Simplified the regex to collect wlan and eth interfaces
* Created the ipv4 and ipv6 keys be default and not when there are ip addresses available
  • Loading branch information
ahmed-mrbeam authored Nov 9, 2022
1 parent 945235d commit c54d146
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions octoprint_findmymrbeam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,22 @@ def _get_netifaces():

# 1. Get all the interfaces names that comply to the regex mentioned, only wlan and eth interfaces
iface_names_list = \
[iface_name for iface_name in netifaces.interfaces() if re.match(r"eth\d.*|wlan\d.*", iface_name) is not None]
[iface_name for iface_name in netifaces.interfaces() if re.match(r"eth\d|wlan\d", iface_name) is not None]

# 2. For each interface, find IPv4 & IPv6 addresses
for iface in iface_names_list:
iface_dict = {
"name": iface,
"addr": {}
"addr": {"ipv4": [], "ipv6": []}
}
iface_addrs = netifaces.ifaddresses(iface)
# 2.a Extract IPv4 if any
if netifaces.AF_INET in iface_addrs:
iface_dict["addr"]["ipv4"] = []
for addr_candidate in iface_addrs[netifaces.AF_INET]:
if not addr_candidate["addr"].startswith("169.254."):
iface_dict["addr"]["ipv4"].append(addr_candidate["addr"])
# 2.b Extract IPv6 if any
if netifaces.AF_INET6 in iface_addrs:
iface_dict["addr"]["ipv6"] = []
for addr_candidate in iface_addrs[netifaces.AF_INET6]:
iface_dict["addr"]["ipv6"].append(addr_candidate["addr"])

Expand Down

0 comments on commit c54d146

Please sign in to comment.