wreq.dns
DNS resolution settings and custom nameservers.
wreq.dns
DNS resolution types and utilities.
LookupIpStrategy
Bases: Enum
IP lookup strategy for DNS resolution.
Determines the order and types of IP addresses to resolve.
Source code in python/wreq/dns.py
IPV4_AND_IPV6
class-attribute
instance-attribute
Resolve both IPv4 and IPv6 addresses.
IPV6_THEN_IPV4
class-attribute
instance-attribute
Prefer IPv6, fall back to IPv4.
DnsOptions
DNS options for customizing DNS resolution behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_dns
|
bool
|
Whether to use the system DNS resolver. Defaults to False, which means using the hickory DNS resolver. |
False
|
lookup_ip_strategy
|
LookupIpStrategy
|
The IP lookup strategy to use. Defaults to IPV4_AND_IPV6. This option only applies to the hickory DNS resolver and has no effect when using the system DNS resolver. |
IPV4_AND_IPV6
|
Example
from wreq import DnsOptions, LookupIpStrategy from ipaddress import IPv4Address options = DnsOptions(LookupIpStrategy.IPV4_ONLY) options.add_resolve("example.com", [IPv4Address("127.0.0.1")])
Source code in python/wreq/dns.py
__init__
Create a new DnsOptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system_dns
|
bool
|
Whether to use the system DNS resolver. When False, the hickory DNS resolver is used. |
False
|
lookup_ip_strategy
|
LookupIpStrategy
|
The IP lookup strategy to use. Only effective when using the hickory DNS resolver. |
IPV4_AND_IPV6
|
Source code in python/wreq/dns.py
add_resolve
Add a custom DNS resolve mapping.
Maps a domain name to a list of IP addresses, bypassing normal DNS resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
str
|
The domain name to map. |
required |
addrs
|
Sequence[IPv4Address | IPv6Address]
|
List of IP addresses to resolve the domain to. |
required |
Example
from ipaddress import IPv4Address, IPv6Address options = DnsOptions() options.add_resolve("api.example.com", [IPv4Address("192.168.1.1")]) options.add_resolve("cdn.example.com", [ ... IPv6Address("2001:db8::1"), ... IPv4Address("203.0.113.1"), ... ])