MCPcopy
hub / github.com/jtesta/ssh-audit / _resolve

Method _resolve

src/ssh_audit/ssh_socket.py:77–97  ·  view source on GitHub ↗

Resolves a hostname into a list of IPs Raises ------ socket.gaierror [Errno -2] If the hostname cannot be resolved.

(self)

Source from the content-addressed store, hash-verified

75 self.client_port = None
76
77 def _resolve(self) -> Iterable[Tuple[int, Tuple[Any, ...]]]:
78 """Resolves a hostname into a list of IPs
79 Raises
80 ------
81 socket.gaierror [Errno -2]
82 If the hostname cannot be resolved.
83 """
84 # If __ip_version_preference has only one entry, then it means that ONLY that IP version should be used.
85 if len(self.__ip_version_preference) == 1:
86 family = socket.AF_INET if self.__ip_version_preference[0] == 4 else socket.AF_INET6
87 else:
88 family = socket.AF_UNSPEC
89 stype = socket.SOCK_STREAM
90 r = socket.getaddrinfo(self.__host, self.__port, family, stype)
91
92 # If the user has a preference for using IPv4 over IPv6 (or vice-versa), then sort the list returned by getaddrinfo() so that the preferred address type comes first.
93 if len(self.__ip_version_preference) == 2:
94 r = sorted(r, key=lambda x: x[0], reverse=(self.__ip_version_preference[0] == 6)) # pylint: disable=superfluous-parens
95 for af, socktype, _proto, _canonname, addr in r:
96 if socktype == socket.SOCK_STREAM:
97 yield af, addr
98
99 # Listens on a server socket and accepts one connection (used for
100 # auditing client connections).

Callers 7

connectMethod · 0.95
test_resolve_errorMethod · 0.80
test_resolve_ipv4Method · 0.80
test_resolve_ipv6Method · 0.80

Calls 1

getaddrinfoMethod · 0.80

Tested by 6

test_resolve_errorMethod · 0.64
test_resolve_ipv4Method · 0.64
test_resolve_ipv6Method · 0.64