PySide6.QtNetwork.QDnsLookup¶
- class QDnsLookup¶
The
QDnsLookup
class represents a DNS lookup. More…Synopsis¶
Properties¶
authenticDataᅟ
- Whether the reply was authenticated by the resolvererrorᅟ
- The type of error that occurred if the DNS lookup failed, or NoErrorerrorStringᅟ
- Human-readable description of the error if the DNS lookup failednameᅟ
- The name to lookupnameserverᅟ
- The nameserver to use for DNS lookupnameserverPortᅟ
- The port number of nameserver to use for DNS lookupnameserverProtocolᅟ
- The protocol to use when sending the DNS querytypeᅟ
- The type of DNS lookup
Methods¶
def
__init__()
def
error()
def
errorString()
def
isFinished()
def
name()
def
nameserver()
def
nameserverPort()
def
pointerRecords()
def
serviceRecords()
def
setName()
def
setNameserver()
def
setType()
def
textRecords()
def
type()
Slots¶
Signals¶
def
finished()
def
nameChanged()
def
typeChanged()
Static functions¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QDnsLookup
uses the mechanisms provided by the operating system to perform DNS lookups. To perform a lookup you need to specify aname
andtype
then invoke thelookup()
slot. Thefinished()
signal will be emitted upon completion.For example, you can determine which servers an XMPP chat client should connect to for a given domain with:
def lookupServers(self): # Create a DNS lookup. dns = QDnsLookup(self) dns.finished.connect(self.handleServers) # Find the XMPP servers for gmail.com dns.setType(QDnsLookup.SRV) dns.setName("_xmpp-client._tcp.gmail.com") dns.lookup()
Once the request finishes you can handle the results with:
def handleServers(self): # Check the lookup succeeded. if dns.error() != QDnsLookup.NoError: qWarning("DNS lookup failed") dns.deleteLater() return # Handle the results. records = dns.serviceRecords() for record in records: ... dns.deleteLater()
Note
If you simply want to find the IP address(es) associated with a host name, or the host name associated with an IP address you should use
QHostInfo
instead.DNS-over-TLS and Authentic Data¶
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, ifQSslSocket
support is present in Qt. To query if support is present at runtime, useisProtocolSupported()
.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
(throughQSslSocket
) only validates that the server presents a certificate that is valid for the server being connected to. Clients may usesetSslConfiguration()
to impose additional restrictions andsslConfiguration()
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, theauthenticData
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.Authentic Data without TLS¶
QDnsLookup
request Authentic Data for any server set withsetNameserver()
, 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, ifsetNameserver()
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.- class Error¶
Indicates all possible error conditions found during the processing of the DNS lookup.
Constant
Description
QDnsLookup.NoError
no error condition.
QDnsLookup.ResolverError
there was an error initializing the system’s DNS resolver.
QDnsLookup.OperationCancelledError
the lookup was aborted using the
abort()
method.QDnsLookup.InvalidRequestError
the requested DNS lookup was invalid.
QDnsLookup.InvalidReplyError
the reply returned by the server was invalid.
QDnsLookup.ServerFailureError
the server encountered an internal failure while processing the request (SERVFAIL).
QDnsLookup.ServerRefusedError
the server refused to process the request for security or policy reasons (REFUSED).
QDnsLookup.NotFoundError
the requested domain name does not exist (NXDOMAIN).
QDnsLookup.TimeoutError
the server was not reached or did not reply in time (since 6.6).
- class Type¶
Indicates the type of DNS lookup that was performed.
Constant
Description
QDnsLookup.A
IPv4 address records.
QDnsLookup.AAAA
IPv6 address records.
QDnsLookup.ANY
any records.
QDnsLookup.CNAME
canonical name records.
QDnsLookup.MX
mail exchange records.
QDnsLookup.NS
name server records.
QDnsLookup.PTR
pointer records.
QDnsLookup.SRV
service records.
QDnsLookup.TLSA
TLS association records.
QDnsLookup.TXT
text records.
- class Protocol¶
Indicates the type of DNS server that is being queried.
Constant
Description
QDnsLookup.Standard
Regular, unencrypted DNS, using UDP and falling back to TCP as necessary (default port: 53)
QDnsLookup.DnsOverTls
Encrypted DNS over TLS (DoT, as specified by RFC 7858), over TCP (default port: 853)
Added in version 6.8.
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- property authenticDataᅟ: 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 withsetNameserver()
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.See also
- Access functions:
Signal
finished()
- property errorᅟ: QDnsLookup.Error¶
This property holds the type of error that occurred if the DNS lookup failed, or
NoError
..- Access functions:
Signal
finished()
- property errorStringᅟ: str¶
This property holds a human-readable description of the error if the DNS lookup failed..
- Access functions:
Signal
finished()
- property nameᅟ: str¶
This property holds the name to lookup..
If the name to look up is empty,
QDnsLookup
will attempt to resolve the root domain of DNS. That query is usually performed withtype
set toNS
.Note
The name will be encoded using IDNA, which means it’s unsuitable for querying SRV records compatible with the DNS-SD specification.
- Access functions:
Signal
nameChanged()
- property nameserverᅟ: QHostAddress¶
This property holds the nameserver to use for DNS lookup..
- Access functions:
- property nameserverPortᅟ: int¶
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 thenameserverProtocol()
.Note
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 usedStandard
. Notably, the Windows API used byQDnsLookup
is unable to handle alternate port numbers.- Access functions:
- property nameserverProtocolᅟ: QDnsLookup.Protocol¶
This property holds the protocol to use when sending the DNS query.
See also
- Access functions:
- property typeᅟ: QDnsLookup.Type¶
This property holds the type of DNS lookup..
- Access functions:
Signal
typeChanged()
Constructs a
QDnsLookup
object and setsparent
as the parent object.The
type
property will default toA
.Constructs a
QDnsLookup
object for the giventype
andname
and setsparent
as the parent object.- __init__(type, name, nameserver[, parent=None])
- Parameters:
type –
Type
name – str
nameserver –
QHostAddress
parent –
QObject
Constructs a
QDnsLookup
object to issue a query forname
of record typetype
, using the DNS servernameserver
running on the default DNS port, and setsparent
as the parent object.- __init__(type, name, nameserver, port[, parent=None])
- Parameters:
type –
Type
name – str
nameserver –
QHostAddress
port – int
parent –
QObject
Constructs a
QDnsLookup
object to issue a query forname
of record typetype
, using the DNS servernameserver
running on portport
, and setsparent
as the parent object.Note
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 usedStandard
. Notably, the Windows API used byQDnsLookup
is unable to handle alternate port numbers.- __init__(type, name, protocol, nameserver[, port=0[, parent=None]])
- Parameters:
type –
Type
name – str
protocol –
Protocol
nameserver –
QHostAddress
port – int
parent –
QObject
Constructs a
QDnsLookup
object to issue a query forname
of record typetype
, using the DNS servernameserver
running on portport
, and setsparent
as the parent object.The query will be sent using
protocol
, if supported. UseisProtocolSupported()
to check if it is supported.Note
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 usedStandard
. Notably, the Windows API used byQDnsLookup
is unable to handle alternate port numbers.- abort()¶
Aborts the DNS lookup operation.
If the lookup is already finished, does nothing.
- canonicalNameRecords()¶
- Return type:
.list of QDnsDomainNameRecord
Returns the list of canonical name records associated with this lookup.
Returns the standard (default) port number for the protocol
protocol
.See also
Getter of property
errorᅟ
.- errorString()¶
- Return type:
str
Getter of property
errorStringᅟ
.- finished()¶
This signal is emitted when the reply has finished processing.
Notification signal of property
errorᅟ
.- hostAddressRecords()¶
- Return type:
.list of QDnsHostAddressRecord
Returns the list of host address records associated with this lookup.
- isAuthenticData()¶
- Return type:
bool
Getter of property
authenticDataᅟ
.- isFinished()¶
- Return type:
bool
Returns whether the reply has finished or was aborted.
Returns true if DNS queries using
protocol
are supported withQDnsLookup
.See also
- lookup()¶
Performs the DNS lookup.
The
finished()
signal is emitted upon completion.- mailExchangeRecords()¶
- Return type:
.list of QDnsMailExchangeRecord
Returns the list of mail exchange records associated with this lookup.
The records are sorted according to RFC 5321 , so if you use them to connect to servers, you should try them in the order they are listed.
Getter of property
nameᅟ
.- nameChanged(name)¶
- Parameters:
name – str
This signal is emitted when the lookup
name
changes.name
is the new lookup name.Notification signal of property
nameᅟ
.- nameServerRecords()¶
- Return type:
.list of QDnsDomainNameRecord
Returns the list of name server records associated with this lookup.
- nameserver()¶
- Return type:
See also
Getter of property
nameserverᅟ
.- nameserverChanged(nameserver)¶
- Parameters:
nameserver –
QHostAddress
Notification signal of property
nameserverᅟ
.- nameserverPort()¶
- Return type:
int
See also
Getter of property
nameserverPortᅟ
.- nameserverPortChanged(port)¶
- Parameters:
port – int
Notification signal of property
nameserverPortᅟ
.- nameserverProtocol()¶
- Return type:
See also
Getter of property
nameserverProtocolᅟ
.Notification signal of property
nameserverProtocolᅟ
.- pointerRecords()¶
- Return type:
.list of QDnsDomainNameRecord
Returns the list of pointer records associated with this lookup.
- serviceRecords()¶
- Return type:
.list of QDnsServiceRecord
Returns the list of service records associated with this lookup.
The records are sorted according to RFC 2782 , so if you use them to connect to servers, you should try them in the order they are listed.
Setter of property
nameᅟ
.- setNameserver(nameserver)¶
- Parameters:
nameserver –
QHostAddress
Setter of property
nameserverᅟ
.- setNameserver(nameserver, port)
- Parameters:
nameserver –
QHostAddress
port – int
Sets the nameserver to
nameserver
and the port toport
.Note
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 usedStandard
. Notably, the Windows API used byQDnsLookup
is unable to handle alternate port numbers.See also
- setNameserver(protocol, nameserver[, port=0])
- Parameters:
protocol –
Protocol
nameserver –
QHostAddress
port – int
- setNameserverPort(port)¶
- Parameters:
port – int
See also
Setter of property
nameserverPortᅟ
.Setter of property
nameserverProtocolᅟ
.- setSslConfiguration(sslConfiguration)¶
- Parameters:
sslConfiguration –
QSslConfiguration
Sets the
sslConfiguration
to use for outgoing DNS-over-TLS connections.See also
Setter of property
typeᅟ
.- sslConfiguration()¶
- Return type:
Returns the current SSL configuration.
See also
- textRecords()¶
- Return type:
.list of QDnsTextRecord
Returns the list of text records associated with this lookup.
- tlsAssociationRecords()¶
- Return type:
.list of QDnsTlsAssociationRecord
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()
for more information.Getter of property
typeᅟ
.This signal is emitted when the lookup
type
changes.type
is the new lookup type.Notification signal of property
typeᅟ
.