♻️ Prefer configured addresses over standard addresses
That way, if OctoPrint is running on a device with network `192.168.1.0/24` and we query with an address from that range, we'll actually get that subnet address back instead of the more general `192.168.0.0/16`.
This commit is contained in:
1 parent
89f3edcb27
commit
e7e731800b
1 file changed
+23
-21
+23
-21
@@ -59,27 +59,6 @@ def get_lan_ranges(additional_private=None):
|
||||
if additional_private is None or not isinstance(additional_private, (list, tuple)):
|
||||
additional_private = []
|
||||
|
||||
subnets = list(netaddr.ip.IPV4_PRIVATE) + [
|
||||
netaddr.ip.IPV4_LOOPBACK,
|
||||
netaddr.ip.IPV4_LINK_LOCAL,
|
||||
]
|
||||
if HAS_V6:
|
||||
subnets += list(netaddr.ip.IPV6_PRIVATE) + [
|
||||
netaddr.IPNetwork(netaddr.ip.IPV6_LOOPBACK),
|
||||
netaddr.ip.IPV6_LINK_LOCAL,
|
||||
]
|
||||
|
||||
for additional in additional_private:
|
||||
try:
|
||||
subnets.append(netaddr.IPNetwork(additional))
|
||||
except Exception:
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.exception(
|
||||
"Error while trying to add additional private network to local subnets: {}".format(
|
||||
additional
|
||||
)
|
||||
)
|
||||
|
||||
def to_ipnetwork(address):
|
||||
prefix = address["netmask"]
|
||||
if "/" in prefix:
|
||||
@@ -89,6 +68,8 @@ def get_lan_ranges(additional_private=None):
|
||||
addr = strip_interface_tag(address["addr"])
|
||||
return netaddr.IPNetwork("{}/{}".format(addr, prefix))
|
||||
|
||||
subnets = []
|
||||
|
||||
for interface in netifaces.interfaces():
|
||||
addrs = netifaces.ifaddresses(interface)
|
||||
for v4 in addrs.get(socket.AF_INET, ()):
|
||||
@@ -114,6 +95,27 @@ def get_lan_ranges(additional_private=None):
|
||||
)
|
||||
)
|
||||
|
||||
for additional in additional_private:
|
||||
try:
|
||||
subnets.append(netaddr.IPNetwork(additional))
|
||||
except Exception:
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.exception(
|
||||
"Error while trying to add additional private network to local subnets: {}".format(
|
||||
additional
|
||||
)
|
||||
)
|
||||
|
||||
subnets += list(netaddr.ip.IPV4_PRIVATE) + [
|
||||
netaddr.ip.IPV4_LOOPBACK,
|
||||
netaddr.ip.IPV4_LINK_LOCAL,
|
||||
]
|
||||
if HAS_V6:
|
||||
subnets += list(netaddr.ip.IPV6_PRIVATE) + [
|
||||
netaddr.IPNetwork(netaddr.ip.IPV6_LOOPBACK),
|
||||
netaddr.ip.IPV6_LINK_LOCAL,
|
||||
]
|
||||
|
||||
return subnets
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user