Use urllib.parse.urlsplit to parse hostname + port, defaulting to localhost:502. Use socket.getaddrinfo to determine the suitable address family, an then attempt to connect for every returned addrinfo.
This implementation is compatible with previous behavior for IPv4 hosts, but it enables connecting to IPv6 hosts as well. Examples of device arguments that were previously supported and are still supported:
localhost
localhost:502
example.com
example:502
192.0.2.1
192.0.2.1:502
Examples of device arguments that are newly supported:
"[2001:db8::1]"
"[2001:db8::1]:502"
"[fe80::1%eth0]"
"[fe80::1%eth0]:502"
In addition, IPv6-only hosts with hostnames that could only be resolved via IPv6 are now also supported.
Use
urllib.parse.urlsplit
to parse hostname + port, defaulting tolocalhost:502
. Usesocket.getaddrinfo
to determine the suitable address family, an then attempt to connect for every returned addrinfo.This implementation is compatible with previous behavior for IPv4 hosts, but it enables connecting to IPv6 hosts as well. Examples of device arguments that were previously supported and are still supported:
localhost
localhost:502
example.com
example:502
192.0.2.1
192.0.2.1:502
Examples of device arguments that are newly supported:
"[2001:db8::1]"
"[2001:db8::1]:502"
"[fe80::1%eth0]"
"[fe80::1%eth0]:502"
In addition, IPv6-only hosts with hostnames that could only be resolved via IPv6 are now also supported.