- class QDnsLookup#
The
QDnsLookup
class represents a DNS lookup. More…Synopsis#
Properties#
errorᅟ
- 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 lookuptypeᅟ
- 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()
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.- 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.TXT
text records.
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.- 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..
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. Notably, the Windows API used by
QDnsLookup
is unable to handle alternate port numbers.- Access functions:
- property typeᅟ: QDnsLookup.Type#
This property holds the type of DNS lookup..
- Access functions:
Signal
typeChanged()
- __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. Notably, the Windows API used by
QDnsLookup
is unable to handle alternate port numbers.- __init__([parent=None])
- Parameters:
parent –
QObject
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.- 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.
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.
- isFinished()#
- Return type:
bool
Returns whether the reply has finished or was aborted.
- 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ᅟ
.- 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
See also
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. Notably, the Windows API used by
QDnsLookup
is unable to handle alternate port numbers.See also
- setNameserverPort(port)#
- Parameters:
port – int
See also
Setter of property
nameserverPortᅟ
.Setter of property
typeᅟ
.- textRecords()#
- Return type:
.list of QDnsTextRecord
Returns the list of text records associated with this lookup.
Getter of property
typeᅟ
.This signal is emitted when the lookup
type
changes.type
is the new lookup type.Notification signal of property
typeᅟ
.