NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
dns_client类 参考

DNS客户端类 更多...

#include <dns_client.hpp>

struct  config
 DNS客户端配置 更多...

Public 成员函数

 dns_client ()
 默认构造函数
 dns_client (config cfg, bool use_tcp=false)
 构造函数
void set_config (config cfg) noexcept
 设置客户端配置
void set_timeout (const milliseconds timeout) noexcept
 设置超时时间
void set_use_tcp (const bool use_tcp) noexcept
 设置是否使用TCP
void set_cache_ttl (const seconds ttl) noexcept
 设置缓存TTL
void set_recursion_desired (const bool rd)
 设置是否期望递归查询(RD)
void set_edns_udp_payload (const uint16_t payload_size) noexcept
 设置EDNS0 UDP载荷大小
void set_dnssec_ok (const bool ok) noexcept
 设置是否请求DNSSEC(DO)
void clear_cache () noexcept
 清空缓存
dns_query_result query (string_view domain, dns_record::raw type=dns_record::A, dns_class qclass=dns_class::INTERNET)
 执行DNS查询
future< dns_query_resultquery_async (const string &domain, dns_record::raw type=dns_record::A, dns_class qclass=dns_class::INTERNET)
 异步DNS查询
vector< stringresolve_a (string_view domain)
 解析A记录(IPv4地址)
vector< stringresolve_aaaa (string_view domain)
 解析AAAA记录(IPv6地址)
vector< stringresolve_cname (string_view domain)
 解析CNAME记录(别名)
vector< stringresolve_mx (string_view domain)
 解析MX记录(邮件交换器)
vector< stringresolve_txt (string_view domain)
 解析TXT记录(文本记录)
vector< dns_srv_recordresolve_srv (string_view domain)
 解析SRV记录(服务定位器)
optional< dns_soa_recordresolve_soa (string_view domain)
 解析SOA记录(授权区域起始)
string reverse_query (string_view ip)
 反向查询(从IP获取域名)
vector< dns_query_resultbatch_query (const vector< string > &domains, dns_record::raw type=dns_record::A)
 批量查询

静态 Public 成员函数

static byte_vector build_query (string_view domain, dns_record::raw type=dns_record::A, dns_class qclass=dns_class::INTERNET, bool rd=true, bool edns_enable=true, bool dnssec_ok=false, uint16_t edns_payload=edns::DEFAULT_UDP_PAYLOAD)
 构建DNS查询消息
static dns_query_result parse_response (const byte_vector &response, uint16_t expected_id=0)
 解析DNS响应消息

详细描述

DNS客户端类

提供DNS查询服务的完整实现,支持缓存、超时控制和多种查询类型。

主要功能:

  • DNS查询(支持A、AAAA、CNAME、MX、TXT等记录类型)
  • DNS缓存(减少重复查询)
  • 同步/异步查询
  • 批量查询
  • 反向查询(PTR记录)
  • TCP/UDP协议自动切换(响应截断时自动切换TCP)

在文件 dns_client.hpp46 行定义.

构造及析构函数说明

◆ dns_client() [1/2]

dns_client::dns_client ( )
inline

默认构造函数

使用默认配置创建DNS客户端。

在文件 dns_client.hpp102 行定义.

引用了 dns_client().

被这些函数引用 dns_client() , 以及 dns_client().

◆ dns_client() [2/2]

dns_client::dns_client ( config cfg,
bool use_tcp = false )
explicit

构造函数

参数
cfg客户端配置
use_tcp是否强制使用TCP
异常
dns_exception配置无效时抛出

引用了 dns_client().

成员函数说明

◆ batch_query()

vector< dns_query_result > dns_client::batch_query ( const vector< string > & domains,
dns_record::raw type = dns_record::A )

批量查询

参数
domains域名列表
type记录类型(默认A记录)
返回
查询结果列表

并发执行多个DNS查询,提高批量查询效率。

引用了 dns_record::A.

◆ build_query()

byte_vector dns_client::build_query ( string_view domain,
dns_record::raw type = dns_record::A,
dns_class qclass = dns_class::INTERNET,
bool rd = true,
bool edns_enable = true,
bool dnssec_ok = false,
uint16_t edns_payload = edns::DEFAULT_UDP_PAYLOAD )
static

构建DNS查询消息

参数
domain域名
type记录类型
qclass查询类
rd是否期望递归
edns_enable是否启用EDNS0
dnssec_ok是否请求DNSSEC
edns_payloadEDNS0 UDP载荷大小
返回
编码后的DNS查询消息

引用了 dns_record::A, edns::DEFAULT_UDP_PAYLOAD , 以及 INTERNET.

◆ parse_response()

dns_query_result dns_client::parse_response ( const byte_vector & response,
uint16_t expected_id = 0 )
static

解析DNS响应消息

参数
response原始响应数据
expected_id期望的查询ID(0表示不校验)
返回
解析后的查询结果
异常
dns_exception解析或校验失败时抛出

◆ query()

执行DNS查询

参数
domain域名
type记录类型(默认A记录)
qclass查询类(默认INTERNET)
返回
查询结果
异常
dns_exception查询失败时抛出

引用了 dns_record::A , 以及 INTERNET.

◆ query_async()

future< dns_query_result > dns_client::query_async ( const string & domain,
dns_record::raw type = dns_record::A,
dns_class qclass = dns_class::INTERNET )

异步DNS查询

参数
domain域名
type记录类型
qclass查询类
返回
future对象,可等待查询结果

引用了 dns_record::A , 以及 INTERNET.

◆ resolve_a()

vector< string > dns_client::resolve_a ( string_view domain)

解析A记录(IPv4地址)

参数
domain域名
返回
IPv4地址列表

◆ resolve_aaaa()

vector< string > dns_client::resolve_aaaa ( string_view domain)

解析AAAA记录(IPv6地址)

参数
domain域名
返回
IPv6地址列表

◆ resolve_cname()

vector< string > dns_client::resolve_cname ( string_view domain)

解析CNAME记录(别名)

参数
domain域名
返回
别名列表

◆ resolve_mx()

vector< string > dns_client::resolve_mx ( string_view domain)

解析MX记录(邮件交换器)

参数
domain域名
返回
MX记录列表(格式:"优先级 域名")

◆ resolve_soa()

optional< dns_soa_record > dns_client::resolve_soa ( string_view domain)

解析SOA记录(授权区域起始)

参数
domain域名
返回
SOA记录,失败返回空optional

◆ resolve_srv()

vector< dns_srv_record > dns_client::resolve_srv ( string_view domain)

解析SRV记录(服务定位器)

参数
domain域名
返回
SRV记录列表

◆ resolve_txt()

vector< string > dns_client::resolve_txt ( string_view domain)

解析TXT记录(文本记录)

参数
domain域名
返回
文本记录列表

◆ reverse_query()

string dns_client::reverse_query ( string_view ip)

反向查询(从IP获取域名)

参数
ipIPv4地址
返回
域名,失败返回空字符串
异常
dns_exceptionIP地址无效时抛出

执行PTR记录查询,将IP地址转换为域名。 支持IPv4地址,IPv6支持有限。

◆ set_cache_ttl()

void dns_client::set_cache_ttl ( const seconds ttl)
inlinenoexcept

设置缓存TTL

参数
ttl缓存生存时间

在文件 dns_client.hpp142 行定义.

◆ set_config()

void dns_client::set_config ( config cfg)
inlinenoexcept

设置客户端配置

参数
cfg新配置

在文件 dns_client.hpp124 行定义.

引用了 move().

◆ set_dnssec_ok()

void dns_client::set_dnssec_ok ( const bool ok)
inlinenoexcept

设置是否请求DNSSEC(DO)

参数
ok是否启用DNSSEC

在文件 dns_client.hpp160 行定义.

◆ set_edns_udp_payload()

void dns_client::set_edns_udp_payload ( const uint16_t payload_size)
inlinenoexcept

设置EDNS0 UDP载荷大小

参数
payload_sizeUDP载荷大小(字节)

在文件 dns_client.hpp154 行定义.

◆ set_recursion_desired()

void dns_client::set_recursion_desired ( const bool rd)
inline

设置是否期望递归查询(RD)

参数
rd是否期望递归

在文件 dns_client.hpp148 行定义.

◆ set_timeout()

void dns_client::set_timeout ( const milliseconds timeout)
inlinenoexcept

设置超时时间

参数
timeout超时时间

在文件 dns_client.hpp130 行定义.

引用了 timeout.

◆ set_use_tcp()

void dns_client::set_use_tcp ( const bool use_tcp)
inlinenoexcept

设置是否使用TCP

参数
use_tcp是否使用TCP

在文件 dns_client.hpp136 行定义.


该类的文档由以下文件生成: