• PySide 模块
  • PySide.QtNetwork
  • 内容表

    上一话题

    QNetworkAddressEntry

    下一话题

    QIPv6Address

    QHostAddress

    概要

    函数

    静态函数

    详细描述

    PySide.QtNetwork.QHostAddress class provides an IP address.

    此类以与平台和协议无关的方式保持 IPv4 或 IPv6 地址。

    PySide.QtNetwork.QHostAddress is normally used with the PySide.QtNetwork.QTcpSocket , PySide.QtNetwork.QTcpServer ,和 PySide.QtNetwork.QUdpSocket 以连接到主机或设置服务器。

    设置主机地址采用 PySide.QtNetwork.QHostAddress.setAddress() , and retrieved with PySide.QtNetwork.QHostAddress.toIPv4Address() , PySide.QtNetwork.QHostAddress.toIPv6Address() ,或 PySide.QtNetwork.QHostAddress.toString() . You can check the type with PySide.QtNetwork.QHostAddress.protocol() .

    注意

    请注意 PySide.QtNetwork.QHostAddress does not do DNS lookups. PySide.QtNetwork.QHostInfo 是需要的为此。

    类还支持常见预定义地址: Null , LocalHost , LocalHostIPv6 , Broadcast ,和 Any .

    class PySide.QtNetwork. QHostAddress
    class PySide.QtNetwork. QHostAddress ( address )
    class PySide.QtNetwork. QHostAddress ( copy )
    class PySide.QtNetwork. QHostAddress ( ip6Addr )
    class PySide.QtNetwork. QHostAddress ( address )
    class PySide.QtNetwork. QHostAddress ( ip4Addr )
    参数:

    Constructs a host address object with the IP address 0.0.0.0.

    构造 PySide.QtNetwork.QHostAddress 对象为 address .

    构造副本为给定 address .

    构造 IPv4 或 IPv6 地址基于字符串 address (e.g., “127.0.0.1”).

    构造主机地址对象采用 IPv4 地址 ip4Addr .

    PySide.QtNetwork.QHostAddress. SpecialAddress
    常量 描述
    QHostAddress.Null null 地址对象。相当于 PySide.QtNetwork.QHostAddress.QHostAddress() .
    QHostAddress.LocalHost Pv4 本地主机地址。相当于 PySide.QtNetwork.QHostAddress (“127.0.0.1”).
    QHostAddress.LocalHostIPv6 IPv6 本地主机地址。相当于 PySide.QtNetwork.QHostAddress (”::1”).
    QHostAddress.Broadcast IPv4 广播地址。相当于 PySide.QtNetwork.QHostAddress (“255.255.255.255”).
    QHostAddress.Any IPv4 任意地址。相当于 PySide.QtNetwork.QHostAddress (“0.0.0.0”).
    QHostAddress.AnyIPv6 IPv6 任意地址。相当于 PySide.QtNetwork.QHostAddress (” . ”).
    PySide.QtNetwork.QHostAddress. clear ( )

    Sets the host address to 0.0.0.0.

    PySide.QtNetwork.QHostAddress. isInSubnet ( subnet )
    参数: subnet
    返回类型: PySide.QtCore.bool
    PySide.QtNetwork.QHostAddress. isInSubnet ( subnet , netmask )
    参数:
    返回类型:

    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.

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

    PySide.QtNetwork.QHostAddress. isNull ( )
    返回类型: 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.

    PySide.QtNetwork.QHostAddress. __ne__ ( address )
    参数: address PySide.QtNetwork.QHostAddress.SpecialAddress
    返回类型: PySide.QtCore.bool

    Returns true if this host address is not the same as the other address given; otherwise returns false.

    PySide.QtNetwork.QHostAddress. __ne__ ( address )
    参数: address PySide.QtNetwork.QHostAddress
    返回类型: PySide.QtCore.bool

    Returns true if this host address is not the same as the other address given; otherwise returns false.

    PySide.QtNetwork.QHostAddress. __eq__ ( address )
    参数: address PySide.QtNetwork.QHostAddress
    返回类型: PySide.QtCore.bool

    Returns true if this host address is the same as the other address given; otherwise returns false.

    PySide.QtNetwork.QHostAddress. __eq__ ( address )
    参数: address PySide.QtNetwork.QHostAddress.SpecialAddress
    返回类型: PySide.QtCore.bool

    Returns true if this host address is the same as the other address given; otherwise returns false.

    static PySide.QtNetwork.QHostAddress. parseSubnet ( subnet )
    参数: subnet – unicode
    返回类型:

    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:

    • 123.123.123.123/n where n is any value between 0 and 32
    • 123.123.123.123/255.255.255.255
    • <ipv6-address>/n where n is any value between 0 and 128

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

    PySide.QtNetwork.QHostAddress. protocol ( )
    返回类型: PySide.QtNetwork.QAbstractSocket.NetworkLayerProtocol

    返回主机地址的网络层协议。

    PySide.QtNetwork.QHostAddress. scopeId ( )
    返回类型: unicode

    返回 IPv6 地址的作用域 ID。对于 IPv4 地址,或者若地址不包含作用域 ID,空 PySide.QtCore.QString 被返回。

    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:

    • Node-local: Addresses that are only used for communicating with services on the same interface (e.g., the loopback interface ”::1”).
    • Link-local: Addresses that are local to the network interface ( link ). There is always one link-local address for each IPv6 interface on your host. Link-local addresses (“fe80...”) are generated from the MAC address of the local network adaptor, and are not guaranteed to be unique.
    • Site-local: Addresses that are local to the site / private network (e.g., the company intranet). Site-local addresses (“fec0...”) are usually distributed by the site router, and are not guaranteed to be unique outside of the local site.
    • Global: For globally routable addresses, such as public servers on the Internet.

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

    PySide.QtNetwork.QHostAddress. setAddress ( ip4Addr )
    参数: ip4Addr PySide.QtCore.quint32

    设置 IPv4 地址指定通过 ip4Addr .

    PySide.QtNetwork.QHostAddress. setAddress ( ip6Addr )
    参数: ip6Addr PySide.QtNetwork.QIPv6Address
    PySide.QtNetwork.QHostAddress. setAddress ( address )
    参数: address – unicode
    返回类型: PySide.QtCore.bool

    这是重载函数。

    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.

    PySide.QtNetwork.QHostAddress. setScopeId ( id )
    参数: id – unicode

    Sets the IPv6 scope ID of the address to id . If the address protocol is not IPv6, this function does nothing.

    PySide.QtNetwork.QHostAddress. toIPv4Address ( )
    返回类型: PySide.QtCore.quint32

    以数字形式返回 IPv4 地址。

    例如:若地址为 127.0.0.1,返回值为 2130706433 (即 0x7f000001)。

    This value is only valid if the Protocol() is IPv4Protocol .

    PySide.QtNetwork.QHostAddress. toIPv6Address ( )
    返回类型: 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 .

    PySide.QtNetwork.QHostAddress. toString ( )
    返回类型: unicode

    以字符串形式返回地址。

    For example, if the address is the IPv4 address 127.0.0.1, the returned string is “127.0.0.1”. For IPv6 the string format will follow the RFC5952 recommendation.