QDnsLookup 類錶示 DNS (域名係統) 查找。 更多...
| 頭: |
#include <QDnsLookup>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Network)
target_link_libraries(mytarget PRIVATE Qt6::Network)
|
| qmake: |
QT += network
|
| 繼承: | QObject |
| enum | Error { NoError, ResolverError, OperationCancelledError, InvalidRequestError, InvalidReplyError, …, TimeoutError } |
| enum | Protocol { Standard, DnsOverTls } |
| enum | Type { A, AAAA, ANY, CNAME, MX, …, TXT } |
|
|
| QDnsLookup (QObject * parent = nullptr) | |
| QDnsLookup (QDnsLookup::Type type , const QString & name , QObject * parent = nullptr) | |
| QDnsLookup (QDnsLookup::Type type , const QString & name , const QHostAddress & nameserver , QObject * parent = nullptr) | |
(從 6.6 起)
|
QDnsLookup (QDnsLookup::Type type , const QString & name , const QHostAddress & nameserver , quint16 port , QObject * parent = nullptr) |
(從 6.8 起)
|
QDnsLookup (QDnsLookup::Type type , const QString & name , QDnsLookup::Protocol protocol , const QHostAddress & nameserver , quint16 port = 0, QObject * parent = nullptr) |
| virtual | ~QDnsLookup () |
| QBindable<QString> | bindableName () |
| QBindable<QHostAddress> | bindableNameserver () |
| QBindable<quint16> | bindableNameserverPort () |
| QBindable<QDnsLookup::Protocol> | bindableNameserverProtocol () |
| QBindable<QDnsLookup::Type> | bindableType () |
| QList<QDnsDomainNameRecord> | canonicalNameRecords () const |
| QDnsLookup::Error | error () const |
| QString | errorString () const |
| QList<QDnsHostAddressRecord> | hostAddressRecords () const |
| bool | isAuthenticData () const |
| bool | isFinished () const |
| QList<QDnsMailExchangeRecord> | mailExchangeRecords () const |
| QString | name () const |
| QList<QDnsDomainNameRecord> | nameServerRecords () const |
| QHostAddress | nameserver () const |
| quint16 | nameserverPort () const |
| QDnsLookup::Protocol | nameserverProtocol () const |
| QList<QDnsDomainNameRecord> | pointerRecords () const |
| QList<QDnsServiceRecord> | serviceRecords () const |
| void | setName (const QString & name ) |
| void | setNameserver (const QHostAddress & nameserver ) |
| void | setNameserver (QDnsLookup::Protocol protocol , const QHostAddress & nameserver , quint16 port = 0) |
(從 6.6 起)
void
|
setNameserver (const QHostAddress & nameserver , quint16 port ) |
| void | setNameserverPort (quint16 port ) |
| void | setNameserverProtocol (QDnsLookup::Protocol protocol ) |
(從 6.8 起)
void
|
setSslConfiguration (const QSslConfiguration & sslConfiguration ) |
| void | setType (QDnsLookup::Type) |
| QSslConfiguration | sslConfiguration () const |
| QList<QDnsTextRecord> | textRecords () const |
(從 6.8 起)
QList<QDnsTlsAssociationRecord>
|
tlsAssociationRecords () const |
| QDnsLookup::Type | type () const |
| void | abort () |
| void | lookup () |
| void | finished () |
| void | nameChanged (const QString & name ) |
| void | nameserverChanged (const QHostAddress & nameserver ) |
| void | nameserverPortChanged (quint16 port ) |
| void | nameserverProtocolChanged (QDnsLookup::Protocol protocol ) |
| void | typeChanged (QDnsLookup::Type type ) |
(從 6.8 起)
quint16
|
defaultPortForProtocol (QDnsLookup::Protocol protocol ) |
(從 6.8 起)
bool
|
isProtocolSupported (QDnsLookup::Protocol protocol ) |
QDnsLookup 使用由操作係統提供的機製來履行 DNS 查找。要履行查找需要指定 name and type 然後援引 lookup () slot. The finished () signal will be emitted upon completion.
例如,可以確定給定域的 XMPP 聊天客戶端應該連接到哪些服務器采用:
void MyObject::lookupServers() { // Create a DNS lookup. dns = new QDnsLookup(this); connect(dns, &QDnsLookup::finished, this, &MyObject::handleServers); // Find the XMPP servers for gmail.com dns->setType(QDnsLookup::SRV); dns->setName("_xmpp-client._tcp.gmail.com"); dns->lookup(); }
一旦請求完成,可以處理結果采用:
void MyObject::handleServers() { // Check the lookup succeeded. if (dns->error() != QDnsLookup::NoError) { qWarning("DNS lookup failed"); dns->deleteLater(); return; } // Handle the results. const auto records = dns->serviceRecords(); for (const QDnsServiceRecord &record : records) { ... } dns->deleteLater(); }
注意: 若僅僅希望查找與主機名關聯的 IP 地址 (或與 IP 地址關聯的主機名),應該使用 QHostInfo 代替。
QDnsLookup supports DNS-over-TLS (DoT, as specified by RFC 7858 ) on some platforms. That currently includes all Unix platforms where regular queries are supported, if QSslSocket support is present in Qt. To query if support is present at runtime, use isProtocolSupported ().
When using DNS-over-TLS, QDnsLookup only implements the "Opportunistic Privacy Profile" method of authentication, as described in RFC 7858 section 4.1. In this mode, QDnsLookup (through QSslSocket ) only validates that the server presents a certificate that is valid for the server being connected to. Clients may use setSslConfiguration () to impose additional restrictions and sslConfiguration () to obtain information after the query is complete.
QDnsLookup will request DNS servers queried over TLS to perform authentication on the data they return. If they confirm the data is valid, the authenticData property will be set to true. QDnsLookup does not verify the integrity of the data by itself, so applications should only trust this property on servers they have confirmed through other means to be trustworthy.
QDnsLookup request Authentic Data for any server set with setNameserver (), even if TLS encryption is not required. This is useful when querying a caching nameserver on the same host as the application or on a trusted network. Though similar to the TLS case, the application is responsible for determining if the server it chose to use is trustworthy, and if the unencrypted connection cannot be tampered with.
QDnsLookup obeys the system configuration to request Authentic Data on the default nameserver (that is, if setNameserver () is not called). This is currently only supported on Linux systems using glibc 2.31 or later. On any other systems, QDnsLookup will ignore the AD bit in the query header.
指示在 DNS 查找處理過程中發現的所有可能的錯誤條件。
| 常量 | 值 | 描述 |
|---|---|---|
QDnsLookup::NoError
|
0
|
沒有錯誤條件。 |
QDnsLookup::ResolverError
|
1
|
初始化係統的 DNS 解析器時齣錯。 |
QDnsLookup::OperationCancelledError
|
2
|
查找被中止使用 abort () 方法。 |
QDnsLookup::InvalidRequestError
|
3
|
請求的 DNS 查找無效。 |
QDnsLookup::InvalidReplyError
|
4
|
由服務器返迴的迴復無效。 |
QDnsLookup::ServerFailureError
|
5
|
服務器遭遇內部故障當處理請求時 (SERVFAIL)。 |
QDnsLookup::ServerRefusedError
|
6
|
服務器齣於安全或策略原因拒絕處理請求 (REFUSED)。 |
QDnsLookup::NotFoundError
|
7
|
請求的域名不存在 (NXDOMAIN)。 |
QDnsLookup::TimeoutError
|
8
|
the server was not reached or did not reply in time (since 6.6). |
Indicates the type of DNS server that is being queried.
| 常量 | 值 | 描述 |
|---|---|---|
QDnsLookup::Standard
|
0
|
Regular, unencrypted DNS, using UDP and falling back to TCP as necessary (default port: 53) |
QDnsLookup::DnsOverTls
|
1
|
Encrypted DNS over TLS (DoT, as specified by RFC 7858 ), over TCP (default port: 853) |
另請參閱 isProtocolSupported (), nameserverProtocol ,和 setNameserver ().
指示所履行的 DNS 查找類型。
| 常量 | 值 | 描述 |
|---|---|---|
QDnsLookup::A
|
1
|
IPv4 地址記錄。 |
QDnsLookup::AAAA
|
28
|
IPv6 地址記錄。 |
QDnsLookup::ANY
|
255
|
任何記錄。 |
QDnsLookup::CNAME
|
5
|
典型名稱記錄。 |
QDnsLookup::MX
|
15
|
郵件交換記錄。 |
QDnsLookup::NS
|
2
|
名稱服務器記錄。 |
QDnsLookup::PTR
|
12
|
指針記錄。 |
QDnsLookup::SRV
|
33
|
服務記錄。 |
QDnsLookup::TLSA (since Qt 6.8)
|
52
|
TLS association records. |
QDnsLookup::TXT
|
16
|
文本記錄。 |
[read-only, since 6.8]
authenticData
: const
bool
This property holds whether the reply was authenticated by the resolver.
QDnsLookup does not perform the authentication itself. Instead, it trusts the name server that was queried to perform the authentication and report it. The application is responsible for determining if any servers it configured with setNameserver () are trustworthy; if no server was set, QDnsLookup obeys system configuration on whether responses should be trusted.
This property may be set even if error () indicates a resolver error occurred.
該特性在 Qt 6.8 引入。
訪問函數:
| bool | isAuthenticData () const |
通知程序信號:
| void | finished () |
另請參閱 setNameserver () 和 nameserverProtocol ().
[read-only]
error
: const
Error
此特性保持齣現錯誤的類型若 DNS 查找失敗,或 NoError .
訪問函數:
| QDnsLookup::Error | error () const |
通知程序信號:
| void | finished () |
[read-only]
errorString
: const
QString
此特性保持錯誤的人類可讀描述,若 DNS 查找失敗。
訪問函數:
| QString | errorString () const |
通知程序信號:
| void | finished () |
[bindable]
名稱
:
QString
注意: 此特性支持 QProperty 綁定。
此特性保持要查找的名稱。
If the name to look up is empty, QDnsLookup will attempt to resolve the root domain of DNS. That query is usually performed with QDnsLookup::type 設為 NS .
注意: 名稱將使用 IDNA 編碼,這意味著它不適閤查詢兼容 DNS-SD 規範的 SRV 記錄。
訪問函數:
| QString | 名稱 () const |
| void | setName (const QString & name ) |
通知程序信號:
| void | nameChanged (const QString & name ) |
[bindable]
nameserver
:
QHostAddress
注意: 此特性支持 QProperty 綁定。
此特性保持用於 DNS 查找的名稱服務器。
訪問函數:
| QHostAddress | nameserver () const |
| void | setNameserver (const QHostAddress & nameserver ) |
| void | setNameserver (QDnsLookup::Protocol protocol , const QHostAddress & nameserver , quint16 port = 0) |
| void | setNameserver (const QHostAddress & nameserver , quint16 port ) |
通知程序信號:
| void | nameserverChanged (const QHostAddress & nameserver ) |
[bindable, since 6.6]
nameserverPort
:
quint16
注意: 此特性支持 QProperty 綁定。
This property holds the port number of nameserver to use for DNS lookup.
The value of 0 indicates that QDnsLookup should use the default port for the nameserverProtocol ().
注意: Setting the port number to any value other than the default (53) can cause the name resolution to fail, depending on the operating system limitations and firewalls, if the nameserverProtocol () to be used QDnsLookup::Standard . Notably, the Windows API used by QDnsLookup is unable to handle alternate port numbers.
該特性在 Qt 6.6 引入。
訪問函數:
| quint16 | nameserverPort () const |
| void | setNameserverPort (quint16 port ) |
通知程序信號:
| void | nameserverPortChanged (quint16 port ) |
[bindable, since 6.8]
nameserverProtocol
:
Protocol
注意: 此特性支持 QProperty 綁定。
This property holds the protocol to use when sending the DNS query
該特性在 Qt 6.8 引入。
訪問函數:
| QDnsLookup::Protocol | nameserverProtocol () const |
| void | setNameserverProtocol (QDnsLookup::Protocol protocol ) |
通知程序信號:
| void | nameserverProtocolChanged (QDnsLookup::Protocol protocol ) |
另請參閱 isProtocolSupported ().
[bindable]
type
:
Type
注意: 此特性支持 QProperty 綁定。
此特性保持 DNS 查找的類型。
訪問函數:
| QDnsLookup::Type | type () const |
| void | setType (QDnsLookup::Type) |
通知程序信號:
| void | typeChanged (QDnsLookup::Type type ) |
[explicit]
QDnsLookup::
QDnsLookup
(
QObject
*
parent
= nullptr)
構造 QDnsLookup 對象並設置 parent 作為父級對象。
The type 特性默認為 QDnsLookup::A .
構造 QDnsLookup 對象為給定 type and name 並設置 parent 作為父級對象。
Constructs a QDnsLookup object to issue a query for name of record type type , using the DNS server nameserver running on the default DNS port, and sets parent 作為父級對象。
[since 6.6]
QDnsLookup::
QDnsLookup
(
QDnsLookup::Type
type
, const
QString
&
name
, const
QHostAddress
&
nameserver
,
quint16
port
,
QObject
*
parent
= nullptr)
Constructs a QDnsLookup object to issue a query for name of record type type , using the DNS server nameserver running on port port , and sets parent 作為父級對象。
注意: Setting the port number to any value other than the default (53) can cause the name resolution to fail, depending on the operating system limitations and firewalls, if the nameserverProtocol () to be used QDnsLookup::Standard . Notably, the Windows API used by QDnsLookup is unable to handle alternate port numbers.
該函數在 Qt 6.6 引入。
[since 6.8]
QDnsLookup::
QDnsLookup
(
QDnsLookup::Type
type
, const
QString
&
name
,
QDnsLookup::Protocol
protocol
, const
QHostAddress
&
nameserver
,
quint16
port
= 0,
QObject
*
parent
= nullptr)
Constructs a QDnsLookup object to issue a query for name of record type type , using the DNS server nameserver running on port port , and sets parent 作為父級對象。
The query will be sent using protocol , if supported. Use isProtocolSupported () to check if it is supported.
注意: Setting the port number to any value other than the default (53) can cause the name resolution to fail, depending on the operating system limitations and firewalls, if the nameserverProtocol () to be used QDnsLookup::Standard . Notably, the Windows API used by QDnsLookup is unable to handle alternate port numbers.
該函數在 Qt 6.8 引入。
[virtual noexcept]
QDnsLookup::
~QDnsLookup
()
銷毀 QDnsLookup 對象。
它是安全的刪除 QDnsLookup 對象即使它尚未完成,簡而言之,也從不會收到其結果。
[slot]
void
QDnsLookup::
abort
()
中止 DNS 查找操作。
若查找已完成,什麼都不做。
返迴關聯此查找的典型名稱記錄列錶。
[static noexcept, since 6.8]
quint16
QDnsLookup::
defaultPortForProtocol
(
QDnsLookup::Protocol
protocol
)
Returns the standard (default) port number for the protocol protocol .
該函數在 Qt 6.8 引入。
另請參閱 isProtocolSupported ().
[signal]
void
QDnsLookup::
finished
()
此信號被發射,當迴復已處理完成。
注意: 通知程序信號對於特性 authenticData , error ,和 errorString .
返迴關聯此查找的主機地址記錄列錶。
返迴迴復是已完成還是被中止。
[static, since 6.8]
bool
QDnsLookup::
isProtocolSupported
(
QDnsLookup::Protocol
protocol
)
Returns true if DNS queries using protocol are supported with QDnsLookup .
該函數在 Qt 6.8 引入。
另請參閱 nameserverProtocol .
[slot]
void
QDnsLookup::
lookup
()
履行 DNS 查找。
The finished () signal is emitted upon completion.
返迴關聯此查找的郵件交換記錄列錶。
記錄的排序是根據 RFC 5321 ,因此,若使用它們連接到服務器,應按照列錶它們的次序嘗試。
[signal]
void
QDnsLookup::
nameChanged
(const
QString
&
name
)
此信號發射,當查找 name 改變。 name 是新的查找名稱。
注意: 通知程序信號對於特性 name .
返迴關聯此查找的名稱服務器記錄列錶。
返迴關聯此查找的指針記錄列錶。
返迴關聯此查找的服務記錄列錶。
記錄的排序是根據 RFC 2782 ,因此,若使用它們連接到服務器,應按照列錶它們的次序嘗試。
[since 6.6]
void
QDnsLookup::
setNameserver
(const
QHostAddress
&
nameserver
,
quint16
port
)
Sets the nameserver to nameserver and the port to port .
注意: Setting the port number to any value other than the default (53) can cause the name resolution to fail, depending on the operating system limitations and firewalls, if the nameserverProtocol () to be used QDnsLookup::Standard . Notably, the Windows API used by QDnsLookup is unable to handle alternate port numbers.
注意: setter 函數對於特性 nameserver .
該函數在 Qt 6.6 引入。
另請參閱 QDnsLookup::nameserver and QDnsLookup::nameserverPort .
[since 6.8]
void
QDnsLookup::
setSslConfiguration
(const
QSslConfiguration
&
sslConfiguration
)
設置 sslConfiguration to use for outgoing DNS-over-TLS connections.
該函數在 Qt 6.8 引入。
另請參閱 sslConfiguration () 和 QSslSocket::setSslConfiguration ().
Returns the current SSL configuration.
另請參閱 setSslConfiguration ().
返迴關聯此查找的文本記錄列錶。
[since 6.8]
QList
<
QDnsTlsAssociationRecord
> QDnsLookup::
tlsAssociationRecords
() const
Returns the list of TLS association records associated with this lookup.
According to the standards relating to DNS-based Authentication of Named Entities (DANE), this field should be ignored and must not be used for verifying the authentity of a given server if the authenticity of the DNS reply cannot itself be confirmed. See isAuthenticData () 瞭解更多信息。
該函數在 Qt 6.8 引入。
[signal]
void
QDnsLookup::
typeChanged
(
QDnsLookup::Type
type
)
此信號發射,當查找 type 改變。 type 是新的查找類型。
注意: 通知程序信號對於特性 type .