PySide6.QtNetwork.QDnsLookup

class QDnsLookup

The QDnsLookup class represents a DNS lookup. More

Inheritance diagram of PySide6.QtNetwork.QDnsLookup

Synopsis

Properties

Methods

Slots

Signals

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 a name and type then invoke the lookup() slot. The finished() 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, 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.

Authentic Data without TLS

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.

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 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.

Access functions:
property errorᅟ: QDnsLookup.Error

This property holds the type of error that occurred if the DNS lookup failed, or NoError ..

Access functions:
property errorStringᅟ: str

This property holds a human-readable description of the error if the DNS lookup failed..

Access functions:
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 with type set to NS .

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:
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 the nameserverProtocol() .

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 used Standard . Notably, the Windows API used by QDnsLookup 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.

Access functions:
property typeᅟ: QDnsLookup.Type

This property holds the type of DNS lookup..

Access functions:
__init__([parent=None])
Parameters:

parentQObject

Constructs a QDnsLookup object and sets parent as the parent object.

The type property will default to A .

__init__(type, name[, parent=None])
Parameters:

Constructs a QDnsLookup object for the given type and name and sets parent as the parent object.

__init__(type, name, nameserver[, parent=None])
Parameters:

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 as the parent object.

__init__(type, name, nameserver, port[, parent=None])
Parameters:

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 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 used Standard . Notably, the Windows API used by QDnsLookup is unable to handle alternate port numbers.

__init__(type, name, protocol, nameserver[, port=0[, parent=None]])
Parameters:

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 as the parent object.

The query will be sent using protocol, if supported. Use isProtocolSupported() 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 used Standard . Notably, the Windows API used by QDnsLookup 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.

static defaultPortForProtocol(protocol)
Parameters:

protocolProtocol

Return type:

int

Returns the standard (default) port number for the protocol protocol.

error()
Return type:

Error

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.

static isProtocolSupported(protocol)
Parameters:

protocolProtocol

Return type:

bool

Returns true if DNS queries using protocol are supported with QDnsLookup .

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.

name()
Return type:

str

See also

setName()

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:

QHostAddress

See also

setNameserver()

Getter of property nameserverᅟ .

nameserverChanged(nameserver)
Parameters:

nameserverQHostAddress

Notification signal of property nameserverᅟ .

nameserverPort()
Return type:

int

Getter of property nameserverPortᅟ .

nameserverPortChanged(port)
Parameters:

port – int

Notification signal of property nameserverPortᅟ .

nameserverProtocol()
Return type:

Protocol

Getter of property nameserverProtocolᅟ .

nameserverProtocolChanged(protocol)
Parameters:

protocolProtocol

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.

setName(name)
Parameters:

name – str

See also

name()

Setter of property nameᅟ .

setNameserver(nameserver)
Parameters:

nameserverQHostAddress

Setter of property nameserverᅟ .

setNameserver(nameserver, port)
Parameters:

Sets the nameserver to nameserver and the port to port.

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 used Standard . Notably, the Windows API used by QDnsLookup is unable to handle alternate port numbers.

setNameserver(protocol, nameserver[, port=0])
Parameters:
setNameserverPort(port)
Parameters:

port – int

See also

nameserverPort()

Setter of property nameserverPortᅟ .

setNameserverProtocol(protocol)
Parameters:

protocolProtocol

Setter of property nameserverProtocolᅟ .

setSslConfiguration(sslConfiguration)
Parameters:

sslConfigurationQSslConfiguration

Sets the sslConfiguration to use for outgoing DNS-over-TLS connections.

setType(arg__1)
Parameters:

arg__1Type

See also

type()

Setter of property typeᅟ .

sslConfiguration()
Return type:

QSslConfiguration

Returns the current SSL configuration.

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.

type()
Return type:

Type

See also

setType()

Getter of property typeᅟ .

typeChanged(type)
Parameters:

typeType

This signal is emitted when the lookup type changes. type is the new lookup type.

Notification signal of property typeᅟ .