The PySide.QtNetwork.QHostAddress class provides an IP address.
This class holds an IPv4 or IPv6 address in a platform- and protocol-independent manner.
PySide.QtNetwork.QHostAddress is normally used with the PySide.QtNetwork.QTcpSocket , PySide.QtNetwork.QTcpServer , and PySide.QtNetwork.QUdpSocket to connect to a host or to set up a server.
A host address is set with PySide.QtNetwork.QHostAddress.setAddress() , and retrieved with PySide.QtNetwork.QHostAddress.toIPv4Address() , PySide.QtNetwork.QHostAddress.toIPv6Address() , or PySide.QtNetwork.QHostAddress.toString() . You can check the type with PySide.QtNetwork.QHostAddress.protocol() .
Note
Please note that PySide.QtNetwork.QHostAddress does not do DNS lookups. PySide.QtNetwork.QHostInfo is needed for that.
The class also supports common predefined addresses: Null , LocalHost , LocalHostIPv6 , Broadcast , and Any .
Parameters: |
|
---|
Constructs a host address object with the IP address 0.0.0.0.
Constructs a PySide.QtNetwork.QHostAddress object for address .
Constructs a copy of the given address .
Constructs an IPv4 or IPv6 address based on the string address (e.g., “127.0.0.1”).
Constructs a host address object with the IPv4 address ip4Addr .
Constant | Description |
---|---|
QHostAddress.Null | The null address object. Equivalent to PySide.QtNetwork.QHostAddress.QHostAddress() . |
QHostAddress.LocalHost | The IPv4 localhost address. Equivalent to PySide.QtNetwork.QHostAddress (“127.0.0.1”). |
QHostAddress.LocalHostIPv6 | The IPv6 localhost address. Equivalent to PySide.QtNetwork.QHostAddress (”::1”). |
QHostAddress.Broadcast | The IPv4 broadcast address. Equivalent to PySide.QtNetwork.QHostAddress (“255.255.255.255”). |
QHostAddress.Any | The IPv4 any-address. Equivalent to PySide.QtNetwork.QHostAddress (“0.0.0.0”). |
QHostAddress.AnyIPv6 | The IPv6 any-address. Equivalent to PySide.QtNetwork.QHostAddress (” . ”). |
Sets the host address to 0.0.0.0.
Parameters: | subnet – |
---|---|
Return type: | PySide.QtCore.bool |
Parameters: |
|
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this IP is in the subnet described by the network prefix subnet and netmask netmask .
An IP is considered to belong to a subnet if it is contained between the lowest and the highest address in that subnet. In the case of IP version 4, the lowest address is the network address, while the highest address is the broadcast address.
The subnet argument does not have to be the actual network address (the lowest address in the subnet). It can be any valid IP belonging to that subnet. In particular, if it is equal to the IP address held by this object, this function will always return true (provided the netmask is a valid value).
Return type: | PySide.QtCore.bool |
---|
Returns true if this host address is null (INADDR_ANY or in6addr_any). The default constructor creates a null address, and that address is not valid for any host or interface.
Parameters: | address – PySide.QtNetwork.QHostAddress.SpecialAddress |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this host address is not the same as the other address given; otherwise returns false.
Parameters: | address – PySide.QtNetwork.QHostAddress |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this host address is not the same as the other address given; otherwise returns false.
Parameters: | address – PySide.QtNetwork.QHostAddress |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this host address is the same as the other address given; otherwise returns false.
Parameters: | address – PySide.QtNetwork.QHostAddress.SpecialAddress |
---|---|
Return type: | PySide.QtCore.bool |
Returns true if this host address is the same as the other address given; otherwise returns false.
Parameters: | subnet – unicode |
---|---|
Return type: |
Parses the IP and subnet information contained in subnet and returns the network prefix for that network and its prefix length.
The IP address and the netmask must be separated by a slash (/).
This function supports arguments in the form:
For IP version 4, this function accepts as well missing trailing components (i.e., less than 4 octets, like “192.168.1”), followed or not by a dot. If the netmask is also missing in that case, it is set to the number of octets actually passed (in the example above, it would be 24, for 3 octets).
Return type: | PySide.QtNetwork.QAbstractSocket.NetworkLayerProtocol |
---|
Returns the network layer protocol of the host address.
Return type: | unicode |
---|
Returns the scope ID of an IPv6 address. For IPv4 addresses, or if the address does not contain a scope ID, an empty PySide.QtCore.QString is returned.
The IPv6 scope ID specifies the scope of reachability for non-global IPv6 addresses, limiting the area in which the address can be used. All IPv6 addresses are associated with such a reachability scope. The scope ID is used to disambiguate addresses that are not guaranteed to be globally unique.
IPv6 specifies the following four levels of reachability:
When using a link-local or site-local address for IPv6 connections, you must specify the scope ID. The scope ID for a link-local address is usually the same as the interface name (e.g., “eth0”, “en1”) or number (e.g., “1”, “2”).
Parameters: | ip6Addr – PySide.QtCore.quint8 |
---|
This is an overloaded function.
Set the IPv6 address specified by ip6Addr .
ip6Addr must be an array of 16 bytes in network byte order (high-order byte first).
Parameters: | ip4Addr – PySide.QtCore.quint32 |
---|
Set the IPv4 address specified by ip4Addr .
Parameters: | ip6Addr – PySide.QtNetwork.QIPv6Address |
---|
Parameters: | address – unicode |
---|---|
Return type: | PySide.QtCore.bool |
This is an overloaded function.
Sets the IPv4 or IPv6 address specified by the string representation specified by address (e.g. “127.0.0.1”). Returns true and sets the address if the address was successfully parsed; otherwise returns false.
Parameters: | id – unicode |
---|
Sets the IPv6 scope ID of the address to id . If the address protocol is not IPv6, this function does nothing.
Return type: | PySide.QtCore.quint32 |
---|
Returns the IPv4 address as a number.
For example, if the address is 127.0.0.1, the returned value is 2130706433 (i.e. 0x7f000001).
This value is only valid if the Protocol() is IPv4Protocol .
Return type: | PySide.QtNetwork.QIPv6Address |
---|
Returns the IPv6 address as a Q_IPV6ADDR structure. The structure consists of 16 unsigned characters.
addr = hostAddr.toIPv6Address()
# addr contains 16 unsigned characters
for i in range(0, 16):
# process addr[i]
This value is only valid if the PySide.QtNetwork.QHostAddress.protocol() is IPv6Protocol .
Return type: | unicode |
---|
Returns the address as a string.
For example, if the address is the IPv4 address 127.0.0.1, the returned string is “127.0.0.1”.