QDnsLookup

The QDnsLookup class represents a DNS lookup. More

Inheritance diagram of PySide2.QtNetwork.QDnsLookup

Synopsis

Functions

Slots

Signals

Detailed Description

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:

void MyObject::lookupServers()
{
    // Create a DNS lookup.
    dns = new QDnsLookup(this);
    connect(dns, SIGNAL(finished()),
            this, SLOT(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:

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();
}

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.

class PySide2.QtNetwork.QDnsLookup(type, name[, parent=None])

PySide2.QtNetwork.QDnsLookup(type, name, nameserver[, parent=None])

PySide2.QtNetwork.QDnsLookup([parent=None])

param type:

Type

param parent:

PySide2.QtCore.QObject

param name:

str

param nameserver:

PySide2.QtNetwork.QHostAddress

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

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

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

The type property will default to A .

PySide2.QtNetwork.QDnsLookup.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).

PySide2.QtNetwork.QDnsLookup.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.TXT

text records.

PySide2.QtNetwork.QDnsLookup.abort()

Aborts the DNS lookup operation.

If the lookup is already finished, does nothing.

PySide2.QtNetwork.QDnsLookup.canonicalNameRecords()
Return type:

Returns the list of canonical name records associated with this lookup.

PySide2.QtNetwork.QDnsLookup.error()
Return type:

Error

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

PySide2.QtNetwork.QDnsLookup.errorString()
Return type:

str

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

PySide2.QtNetwork.QDnsLookup.finished()
PySide2.QtNetwork.QDnsLookup.hostAddressRecords()
Return type:

Returns the list of host address records associated with this lookup.

PySide2.QtNetwork.QDnsLookup.isFinished()
Return type:

bool

Returns whether the reply has finished or was aborted.

PySide2.QtNetwork.QDnsLookup.lookup()

Performs the DNS lookup.

The finished() signal is emitted upon completion.

PySide2.QtNetwork.QDnsLookup.mailExchangeRecords()
Return type:

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.

PySide2.QtNetwork.QDnsLookup.name()
Return type:

str

This property holds the name to lookup..

Note

The name will be encoded using IDNA, which means it’s unsuitable for querying SRV records compatible with the DNS-SD specification.

PySide2.QtNetwork.QDnsLookup.nameChanged(name)
Parameters:

name – str

PySide2.QtNetwork.QDnsLookup.nameServerRecords()
Return type:

Returns the list of name server records associated with this lookup.

PySide2.QtNetwork.QDnsLookup.nameserver()
Return type:

PySide2.QtNetwork.QHostAddress

This property holds the nameserver to use for DNS lookup..

PySide2.QtNetwork.QDnsLookup.nameserverChanged(nameserver)
Parameters:

nameserverPySide2.QtNetwork.QHostAddress

PySide2.QtNetwork.QDnsLookup.pointerRecords()
Return type:

Returns the list of pointer records associated with this lookup.

PySide2.QtNetwork.QDnsLookup.serviceRecords()
Return type:

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.

PySide2.QtNetwork.QDnsLookup.setName(name)
Parameters:

name – str

This property holds the name to lookup..

Note

The name will be encoded using IDNA, which means it’s unsuitable for querying SRV records compatible with the DNS-SD specification.

PySide2.QtNetwork.QDnsLookup.setNameserver(nameserver)
Parameters:

nameserverPySide2.QtNetwork.QHostAddress

This property holds the nameserver to use for DNS lookup..

PySide2.QtNetwork.QDnsLookup.setType(arg__1)
Parameters:

arg__1Type

This property holds the type of DNS lookup..

PySide2.QtNetwork.QDnsLookup.textRecords()
Return type:

Returns the list of text records associated with this lookup.

PySide2.QtNetwork.QDnsLookup.type()
Return type:

Type

This property holds the type of DNS lookup..

PySide2.QtNetwork.QDnsLookup.typeChanged(type)
Parameters:

typeType