QHostInfo

Inheritance diagram of QHostInfo

Synopsis

Functions

Static functions

Detailed Description

The PySide.QtNetwork.QHostInfo class provides static functions for host name lookups.

PySide.QtNetwork.QHostInfo uses the lookup mechanisms provided by the operating system to find the IP address(es) associated with a host name, or the host name associated with an IP address. The class provides two static convenience functions: one that works asynchronously and emits a signal once the host is found, and one that blocks and returns a PySide.QtNetwork.QHostInfo object.

To look up a host’s IP addresses asynchronously, call PySide.QtNetwork.QHostInfo.lookupHost() , which takes the host name or IP address, a receiver object, and a slot signature as arguments and returns an ID. You can abort the lookup by calling PySide.QtNetwork.QHostInfo.abortHostLookup() with the lookup ID.

Example:

# To find the IP address of qtsoftware.com
QHostInfo.lookupHost("qtsoftware.com", self, SLOT("printResults(QHostInfo)"))

# To find the host name for 4.2.2.1
QHostInfo.lookupHost("4.2.2.1", self, SLOT("printResults(QHostInfo)"))

The slot is invoked when the results are ready. (If you use Qt for Embedded Linux and disabled multithreading support by defining QT_NO_THREAD , PySide.QtNetwork.QHostInfo.lookupHost() will block until the lookup has finished.) The results are stored in a PySide.QtNetwork.QHostInfo object. Call PySide.QtNetwork.QHostInfo.addresses() to get the list of IP addresses for the host, and PySide.QtNetwork.QHostInfo.hostName() to get the host name that was looked up.

If the lookup failed, PySide.QtNetwork.QHostInfo.error() returns the type of error that occurred. PySide.QtNetwork.QHostInfo.errorString() gives a human-readable description of the lookup error.

If you want a blocking lookup, use the QHostInfo.fromName() function:

info = QHostInfo.fromName("qtsoftware.com")

PySide.QtNetwork.QHostInfo supports Internationalized Domain Names (IDNs) through the IDNA and Punycode standards.

To retrieve the name of the local host, use the static QHostInfo.localHostName() function.

Note

Since Qt 4.6.1 PySide.QtNetwork.QHostInfo is using multiple threads for DNS lookup instead of one dedicated DNS thread. This improves performance, but also changes the order of signal emissions when using PySide.QtNetwork.QHostInfo.lookupHost() compared to previous versions of Qt. Note: Since Qt 4.6.3 PySide.QtNetwork.QHostInfo is using a small internal 60 second DNS cache for performance improvements.

class PySide.QtNetwork.QHostInfo(d)
class PySide.QtNetwork.QHostInfo([lookupId=-1])
Parameters:

Constructs a copy of other .

Constructs an empty host info object with lookup ID id .

PySide.QtNetwork.QHostInfo.HostInfoError

This enum describes the various errors that can occur when trying to resolve a host name.

Constant Description
QHostInfo.NoError The lookup was successful.
QHostInfo.HostNotFound No IP addresses were found for the host.
QHostInfo.UnknownError An unknown error occurred.
static PySide.QtNetwork.QHostInfo.abortHostLookup(lookupId)
Parameters:lookupIdPySide.QtCore.int

Aborts the host lookup with the ID id , as returned by PySide.QtNetwork.QHostInfo.lookupHost() .

PySide.QtNetwork.QHostInfo.addresses()
Return type:

Returns the list of IP addresses associated with PySide.QtNetwork.QHostInfo.hostName() . This list may be empty.

Example:

info = QHostInfo()
...
if not info.addresses().isEmpty():
    address = info.addresses().first()
    # use the first IP address
PySide.QtNetwork.QHostInfo.error()
Return type:PySide.QtNetwork.QHostInfo.HostInfoError

Returns the type of error that occurred if the host name lookup failed; otherwise returns NoError .

PySide.QtNetwork.QHostInfo.errorString()
Return type:unicode

If the lookup failed, this function returns a human readable description of the error; otherwise “Unknown error” is returned.

static PySide.QtNetwork.QHostInfo.fromName(name)
Parameters:name – unicode
Return type:PySide.QtNetwork.QHostInfo

Looks up the IP address(es) for the given host name . The function blocks during the lookup which means that execution of the program is suspended until the results of the lookup are ready. Returns the result of the lookup in a PySide.QtNetwork.QHostInfo object.

If you pass a literal IP address to name instead of a host name, PySide.QtNetwork.QHostInfo will search for the domain name for the IP (i.e., PySide.QtNetwork.QHostInfo will perform a reverse lookup). On success, the returned PySide.QtNetwork.QHostInfo will contain both the resolved domain name and IP addresses for the host name.

PySide.QtNetwork.QHostInfo.hostName()
Return type:unicode

Returns the name of the host whose IP addresses were looked up.

static PySide.QtNetwork.QHostInfo.localDomainName()
Return type:unicode

Returns the DNS domain of this machine.

Note: DNS domains are not related to domain names found in Windows networks.

static PySide.QtNetwork.QHostInfo.localHostName()
Return type:unicode

Returns the host name of this machine.

static PySide.QtNetwork.QHostInfo.lookupHost(name, receiver, member)
Parameters:
Return type:

PySide.QtCore.int

PySide.QtNetwork.QHostInfo.lookupId()
Return type:PySide.QtCore.int

Returns the ID of this lookup.

PySide.QtNetwork.QHostInfo.setAddresses(addresses)
Parameters:addresses
PySide.QtNetwork.QHostInfo.setError(error)
Parameters:errorPySide.QtNetwork.QHostInfo.HostInfoError

Sets the error type of this PySide.QtNetwork.QHostInfo to error .

PySide.QtNetwork.QHostInfo.setErrorString(errorString)
Parameters:errorString – unicode

Sets the human readable description of the error that occurred to str if the lookup failed.

PySide.QtNetwork.QHostInfo.setHostName(name)
Parameters:name – unicode

Sets the host name of this PySide.QtNetwork.QHostInfo to hostName .

PySide.QtNetwork.QHostInfo.setLookupId(id)
Parameters:idPySide.QtCore.int

Sets the ID of this lookup to id .