DNS¶
netutils.dns
¶
Functions for working with DNS.
fqdn_to_ip(hostname)
¶
Provides the IP address(es) of a resolvable name on the machine it is running from.
There are many reasons that a valid FQDN may not be resolvable, such as a network error from your machine to the DNS server, an upstream DNS issue, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
An FQDN that may or may not be resolvable. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The IP Address as a string if only one is found, or a list of IP addresses if multiple are found. |
Examples:
>>> from netutils.dns import fqdn_to_ip
>>> from netutils.ip import is_ip
>>> is_ip(fqdn_to_ip("google.com"))
True
>>>
Raises:
| Type | Description |
|---|---|
gaierror
|
If FQDN is not resolvable, leverage is_fqdn_resolvable to check first. |
Source code in netutils/dns.py
is_fqdn_resolvable(hostname)
¶
Verifies whether a hostname is resolvable on the machine it is running from.
There are many reasons that a valid FQDN may not be resolvable, such as a network error from your machine to the DNS server, an upstream DNS issue, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
A FQDN that may or may not be resolvable. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
The result as to whether or not the domain was valid. |
Examples:
>>> from netutils.dns import is_fqdn_resolvable
>>> is_fqdn_resolvable("google.com")
True
>>> is_fqdn_resolvable("nevergonnagiveyouup.pizza")
False
>>>