QHostAddressclass provides an IP address. 更多 …
def
__eq__
(address)
def
__eq__
(address)
def
__ne__
(address)
def
__ne__
(address)
def
clear
()
def
isBroadcast
()
def
isEqual
(address[, mode=QHostAddress.TolerantConversion])
def
isGlobal
()
def
isInSubnet
(subnet)
def
isInSubnet
(subnet, netmask)
def
isLinkLocal
()
def
isLoopback
()
def
isMulticast
()
def
isNull
()
def
isSiteLocal
()
def
isUniqueLocalUnicast
()
def
operator=
(address)
def
operator=
(address)
def
protocol
()
def
scopeId
()
def
setAddress
(address)
def
setAddress
(address)
def
setAddress
(ip4Addr)
def
setAddress
(ip6Addr)
def
setScopeId
(id)
def
swap
(other)
def
toIPv4Address
()
def
toIPv4Address
(ok)
def
toIPv6Address
()
def
toString
()
def
parseSubnet
(subnet)
此类以与平台和协议无关的方式保持 IPv4 或 IPv6 地址。
QHostAddressis normally used with theQTcpSocket,QTcpServer,和QUdpSocket以连接到主机或设置服务器。设置主机地址采用
setAddress(), and retrieved withtoIPv4Address(),toIPv6Address(),或toString(). You can check the type withprotocol().注意
请注意
QHostAddressdoes not do DNS lookups.QHostInfo是需要的为此。类还支持常见预定义地址:
Null,LocalHost,LocalHostIPv6,Broadcast,和Any.
QHostAddress
¶
QHostAddress(address)
QHostAddress(copy)
QHostAddress(ip6Addr)
QHostAddress(address)
QHostAddress(ip4Addr)
- param address
SpecialAddress- param ip6Addr
- param copy
- param ip4Addr
quint32
构造 null 主机地址对象,即:对任何主机或接口无效的地址。
另请参阅
构造
QHostAddress
对象为
address
.
构造主机地址对象采用 IPv4 地址
ip4Addr
.
PySide2.QtNetwork.QHostAddress.
SpecialAddress
¶
|
常量 |
描述 |
|---|---|
|
QHostAddress.Null |
null 地址对象。相当于
|
|
QHostAddress.LocalHost |
Pv4 本地主机地址。相当于
|
|
QHostAddress.LocalHostIPv6 |
IPv6 本地主机地址。相当于
|
|
QHostAddress.Broadcast |
IPv4 广播地址。相当于
|
|
QHostAddress.AnyIPv4 |
IPv4 任意地址。相当于
|
|
QHostAddress.AnyIPv6 |
IPv6 任意地址。相当于
|
|
QHostAddress.Any |
双堆栈任意地址。与此地址绑定的套接字将监听 IPv4 和 IPv6 接口。 |
PySide2.QtNetwork.QHostAddress.
ConversionModeFlag
¶
|
常量 |
描述 |
|---|---|
|
QHostAddress.StrictConversion |
Don’t convert IPv6 addresses to IPv4 when comparing two
|
|
QHostAddress.ConvertV4MappedToIPv4 |
转换 IPv4 映射 IPv6 地址 (RFC 4291 第 2.5.5.2 章节) 当比较时。因此
|
|
QHostAddress.ConvertV4CompatToIPv4 |
转换 IPv4 兼容 IPv6 地址 (RFC 4291 第 2.5.5.1 章节) 当比较时。因此
|
|
QHostAddress.ConvertLocalHost |
转换 IPv6 回送地址为其等效 IPv4 当比较时。因此如
|
|
QHostAddress.ConvertUnspecifiedAddress |
所有未指定地址比较相等,也就是
|
|
QHostAddress.TolerantConversion |
设置之前的所有 3 标志。 |
另请参阅
New in version 5.8.
PySide2.QtNetwork.QHostAddress.
clear
(
)
¶
把主机地址设为 null 并把协议设为
UnknownNetworkLayerProtocol
.
另请参阅
Null
PySide2.QtNetwork.QHostAddress.
isBroadcast
(
)
¶
bool
返回
true
若地址是 IPv4 广播地址,
false
否则。IPv4 广播地址为 255.255.255.255。
Note that this function does not return true for an IPv4 network’s local broadcast address. For that, please use
QNetworkInterface
获取本地机器的广播地址。
PySide2.QtNetwork.QHostAddress.
isEqual
(
address
[
,
mode=QHostAddress.TolerantConversion
]
)
¶
address
–
QHostAddress
mode
–
ConversionMode
bool
返回
true
若此主机地址如同
other
给定地址;否则返回
false
.
参数
mode
controls which conversions are preformed between addresses of differing protocols. If no
mode
被给定,
TolerantConversion
默认履行。
另请参阅
ConversionMode
operator==()
PySide2.QtNetwork.QHostAddress.
isGlobal
(
)
¶
bool
返回
true
若地址是 IPv4 或 IPv6 全局地址,
false
otherwise. A global address is an address that is not reserved for special purposes (like loopback or multicast) or future purposes.
注意,IPv6 唯一本地单播地址被视为是全局地址 (见
isUniqueLocalUnicast()
), as are IPv4 addresses reserved for local networks by
RFC 1918
.
Also note that IPv6 site-local addresses are deprecated and should be considered as global in new applications. This function returns true for site-local addresses too.
PySide2.QtNetwork.QHostAddress.
isInSubnet
(
subnet
,
netmask
)
¶
subnet
–
QHostAddress
netmask
–
int
bool
返回
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).
另请参阅
PySide2.QtNetwork.QHostAddress.
isInSubnet
(
subnet
)
¶
subnet –
bool
这是重载函数。
返回
true
若此 IP 在子网中描述由
subnet
。
QHostAddress
member of
subnet
contains the network prefix and the int (second) member contains the netmask (prefix length).
PySide2.QtNetwork.QHostAddress.
isLinkLocal
(
)
¶
bool
返回
true
若地址是 IPv4 或 IPv6 本地链接地址,
false
否则。
An IPv4 link-local address is an address in the network 169.254.0.0/16. An IPv6 link-local address is one in the network fe80::/10. See the IANA IPv6 Address Space registry for more information.
PySide2.QtNetwork.QHostAddress.
isLoopback
(
)
¶
bool
返回
true
若地址是 IPv6 回环地址或任何 IPv4 回环地址。
PySide2.QtNetwork.QHostAddress.
isMulticast
(
)
¶
bool
返回
true
若地址是 IPv4 或 IPv6 多播地址,
false
否则。
PySide2.QtNetwork.QHostAddress.
isNull
(
)
¶
bool
返回
true
若此主机地址无效,对于任何主机或接口。
默认构造函数创建 null 地址。
另请参阅
Null
PySide2.QtNetwork.QHostAddress.
isSiteLocal
(
)
¶
bool
返回
true
若地址是 IPv6 本地站点地址,
false
否则。
An IPv6 site-local address is one in the network fec0::/10. See the IANA IPv6 Address Space registry for more information.
IPv6 site-local addresses are deprecated and should not be depended upon in new applications. New applications should not depend on this function and should consider site-local addresses the same as global (which is why
isGlobal()
also returns true). Site-local addresses were replaced by Unique Local Addresses (ULA).
PySide2.QtNetwork.QHostAddress.
isUniqueLocalUnicast
(
)
¶
bool
返回
true
if the address is an IPv6 unique local unicast address,
false
否则。
An IPv6 unique local unicast address is one in the network fc00::/7. See the IANA IPv6 Address Space registry for more information.
Note that Unique local unicast addresses count as global addresses too. RFC 4193 says that, in practice, “applications may treat these addresses like global scoped addresses.” Only routers need care about the distinction.
PySide2.QtNetwork.QHostAddress.
__ne__
(
address
)
¶
address
–
QHostAddress
bool
PySide2.QtNetwork.QHostAddress.
__ne__
(
address
)
¶
address
–
SpecialAddress
bool
返回
true
if this host address is not the same as the
other
给定地址;否则返回
false
.
PySide2.QtNetwork.QHostAddress.operator=(address)
address
–
SpecialAddress
赋值特殊地址
address
到此对象,并返回此对象的引用。
另请参阅
PySide2.QtNetwork.QHostAddress.operator=(address)
address – unicode
注意
此函数被弃用。
PySide2.QtNetwork.QHostAddress.
__eq__
(
address
)
¶
address
–
SpecialAddress
bool
返回
true
若此主机地址如同
other
给定地址;否则返回
false
.
PySide2.QtNetwork.QHostAddress.
__eq__
(
address
)
¶
address
–
QHostAddress
bool
PySide2.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).
另请参阅
PySide2.QtNetwork.QHostAddress.
protocol
(
)
¶
NetworkLayerProtocol
返回主机地址的网络层协议。
PySide2.QtNetwork.QHostAddress.
scopeId
(
)
¶
unicode
返回 IPv6 地址的作用域 ID。对于 IPv4 地址,或者若地址不包含作用域 ID,空
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.
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”).
PySide2.QtNetwork.QHostAddress.
setAddress
(
address
)
¶
address
–
SpecialAddress
这是重载函数。
Sets the special address specified by
address
.
PySide2.QtNetwork.QHostAddress.
setAddress
(
ip4Addr
)
¶
ip4Addr
–
quint32
设置 IPv4 地址指定通过
ip4Addr
.
PySide2.QtNetwork.QHostAddress.
setAddress
(
address
)
¶
address – unicode
bool
PySide2.QtNetwork.QHostAddress.
setAddress
(
ip6Addr
)
¶
ip6Addr
–
QIPv6Address
PySide2.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. The scope ID may be set as an interface name (such as “eth0” or “en1”) or as an integer representing the interface index. If
id
is an interface name,
QtNetwork
will convert to an interface index using
interfaceIndexFromName()
before calling the operating system networking functions.
PySide2.QtNetwork.QHostAddress.
swap
(
other
)
¶
other
–
QHostAddress
交换此主机地址采用
other
。此操作非常快且从不失败。
PySide2.QtNetwork.QHostAddress.
toIPv4Address
(
)
¶
quint32
以数字形式返回 IPv4 地址。
例如:若地址为 127.0.0.1,返回值为 2130706433 (即 0x7f000001)。
此值有效若
protocol()
is
IPv4Protocol
,或者若协议是
IPv6Protocol
, and the IPv6 address is an IPv4 mapped address. (RFC4291)
另请参阅
PySide2.QtNetwork.QHostAddress.
toIPv4Address
(
ok
)
¶
ok
–
bool
quint32
以数字形式返回 IPv4 地址。
例如:若地址为 127.0.0.1,返回值为 2130706433 (即 0x7f000001)。
此值有效若
protocol()
is
IPv4Protocol
,或者若协议是
IPv6Protocol
, and the IPv6 address is an IPv4 mapped address. (RFC4291). In those cases,
ok
will be set to true. Otherwise, it will be set to false.
另请参阅
PySide2.QtNetwork.QHostAddress.
toIPv6Address
(
)
¶
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]
此值有效若
protocol()
is
IPv6Protocol
。若协议是
IPv4Protocol
, then the address is returned an an IPv4 mapped IPv6 address. (RFC4291)
另请参阅
PySide2.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. For
Any
, its IPv4 address will be returned (“0.0.0.0”)
另请参阅