Skip to content

Commit 686febd

Browse files
authored
Strip scope_id from IPv6 address if given. (#1020)
1 parent 4b9a6c3 commit 686febd

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

tests/utils/test_net.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_ip6_to_address_and_index():
3939
"""Test we can extract from mocked adapters."""
4040
adapters = _generate_mock_adapters()
4141
assert netutils.ip6_to_address_and_index(adapters, "2001:db8::") == (('2001:db8::', 1, 1), 1)
42+
assert netutils.ip6_to_address_and_index(adapters, "2001:db8::%1") == (('2001:db8::', 1, 1), 1)
4243
with pytest.raises(RuntimeError):
4344
assert netutils.ip6_to_address_and_index(adapters, "2005:db8::")
4445

zeroconf/_utils/net.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ def get_all_addresses_v6() -> List[Tuple[Tuple[str, int, int], int]]:
8383

8484

8585
def ip6_to_address_and_index(adapters: List[Any], ip: str) -> Tuple[Tuple[str, int, int], int]:
86+
if '%' in ip:
87+
ip = ip[: ip.index('%')] # Strip scope_id.
8688
ipaddr = ipaddress.ip_address(ip)
8789
for adapter in adapters:
8890
for adapter_ip in adapter.ips:

0 commit comments

Comments
 (0)