Resolve a hostname or FQDN to an IP address. Depending on the name specified in parameters, several IP addresses may be returned.
This function relies on the DNS name server configured on your operating system.
resolve(name, family=None)
-
name
A hostname or a Fully Qualified Domain Name (FQDN).
- Type:
str
- Type:
-
family
The address family. Can be set to
4
for IPv4 or6
for IPv6 addresses. By default, this function searches for IPv4 addresses first for compatibility reasons (A DNS lookup) before searching for IPv6 addresses (AAAA DNS lookup).- Type:
int
- Default:
None
- Type:
- A list of IP addresses corresponding to the name passed as a parameter.
-
If you pass a hostname or FQDN in parameters and it does not exist or cannot be resolved.
>>> from icmplib import resolve
>>> resolve('one.one.one.one')
['1.0.0.1', '1.1.1.1']
>>> resolve('localhost')
['127.0.0.1']
>>> resolve('ipv6.google.com')
['2a00:1450:4007:813::200e']
Resolve a hostname or FQDN to an IP address. Depending on the name specified in parameters, several IP addresses may be returned.
This function relies on the DNS name server configured on your operating system.
This function is non-blocking.
async_resolve(name, family=None)
The same parameters, return values and exceptions as for the resolve
function.
>>> import asyncio
>>> from icmplib import async_resolve
>>> asyncio.run(async_resolve('one.one.one.one'))
['1.0.0.1', '1.1.1.1']
>>> asyncio.run(async_resolve('localhost'))
['127.0.0.1']
>>> asyncio.run(async_resolve('ipv6.google.com'))
['2a00:1450:4007:813::200e']
Indicate whether the specified name is a hostname or an FQDN.
is_hostname(address)
>>> from icmplib import is_hostname
>>> is_hostname('one.one.one.one')
True
>>> is_hostname('localhost')
True
>>> is_hostname('127.0.0.1')
False
>>> is_hostname('2a00:1450:4007:813::200e')
False
Indicate whether the specified address is an IPv4 address.
This function does not perform a strict checking. Its does not check if each byte of the IP address is within the allowed range.
This function has been designed to be fast.
is_ipv4_address(address)
>>> from icmplib import is_ipv4_address
>>> is_ipv4_address('one.one.one.one')
False
>>> is_ipv4_address('localhost')
False
>>> is_ipv4_address('127.0.0.1')
True
>>> is_ipv4_address('2a00:1450:4007:813::200e')
False
Indicate whether the specified address is an IPv4 address.
This function does not perform a strict checking. Its does not check if each byte of the IP address is within the allowed range.
This function has been designed to be fast.
is_ipv6_address(address)
>>> from icmplib import is_ipv6_address
>>> is_ipv6_address('one.one.one.one')
False
>>> is_ipv6_address('localhost')
False
>>> is_ipv6_address('127.0.0.1')
False
>>> is_ipv6_address('2a00:1450:4007:813::200e')
True