get_rdns_multi¶
-
privex.helpers.net.get_rdns_multi(*hosts: Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address], throw=False) → Generator[Tuple[str, Optional[str]], None, None][source]¶ Resolve reverse DNS hostnames for multiple IPs / domains specified as positional arguments.
Each host in
hostscan be an IP address as astr,IPv4Address,IPv6Address- or a domain.Returns results as a generator, to allow for efficient handling of a large amount of hosts to resolve.
Basic usage:
>>> for host, rdns in get_rdns_multi('185.130.44.10', '8.8.4.4', '1.1.1.1', '2a07:e00::333'): >>> print(f"{host:<20} -> {rdns:>5}") 185.130.44.10 -> web-se1.privex.io 8.8.4.4 -> dns.google 1.1.1.1 -> one.one.one.one 2a07:e00::333 -> se.dns.privex.io
If you’re only resolving a small number of hosts ( less than 100 or so ), you can simply cast the generator into a
dictusingdict(), which will get you a dictionary of hosts mapped to their rDNS:>>> data = dict(get_rdns_multi('185.130.44.10', '8.8.4.4', '1.1.1.1', '2a07:e00::333')) >>> data['8.8.4.4'] 'dns.google' >>> data.get('2a07:e00::333', 'error') 'se.dns.privex.io'
- Parameters
hosts (str|IPv4Address|IPv6Address) – One or more IPv4/v6 addresses, or domains to lookup reverse DNS for - as positional args.
throw (bool) – (Default:
False) WhenTrue, will raiseReverseDNSNotFoundorInvalidHostwhen no rDNS records can be found for a host, or when the host is an invalid IP / non-existent domain. WhenFalse, will simply returnNonewhen a host is invalid, or no rDNS records are found.
- Raises
ReverseDNSNotFound – When
throwis True and no rDNS records were found forhostInvalidHost – When
throwis True andhostis an invalid IP address or non-existent domain/hostname
- Return Tuple[str,Optional[str]] rDNS
A generator returning
tuple’s containing the original passed host, and it’s reverse DNS hostname (value of PTR record)