InetAddress#
Superclasses: Object
GInetAddress represents an IPv4 or IPv6 internet address. Use
lookup_by_name or
lookup_by_name_async to look up the GInetAddress for
a hostname. Use lookup_by_address or
lookup_by_address_async to look up the hostname for a
GInetAddress.
To actually connect to a remote host, you will need a
InetSocketAddress (which includes a GInetAddress as well as a
port number).
Constructors#
- class InetAddress
- classmethod new_any(family: SocketFamily) InetAddress#
Creates a
InetAddressfor the “any” address (unassigned/”don’t care”) forfamily.Added in version 2.22.
- Parameters:
family – the address family
- classmethod new_from_bytes(bytes: list[int], family: SocketFamily) InetAddress#
Creates a new
InetAddressfrom the givenfamilyandbytes.bytesshould be 4 bytes forIPV4and 16 bytes forIPV6.Added in version 2.22.
- Parameters:
bytes – raw address data
family – the address family of
bytes
- classmethod new_from_bytes_with_ipv6_info(bytes: list[int], family: SocketFamily, flowinfo: int, scope_id: int) InetAddress#
Creates a new
InetAddressfrom the givenfamily,bytesandscope_id.bytesmust be 4 bytes forIPV4and 16 bytes forIPV6.Added in version 2.86.
- Parameters:
bytes – raw address data
family – the address family of
bytesflowinfo
scope_id – the scope-id of the address
- classmethod new_from_string(string: str) InetAddress | None#
Parses
stringas an IP address and creates a newInetAddress.If
addressis an IPv6 address, it can also contain a scope ID (separated from the address by a%). Note that currently this behavior is platform specific. This may change in a future release.Added in version 2.22.
- Parameters:
string – a string representation of an IP address
- classmethod new_loopback(family: SocketFamily) InetAddress#
Creates a
InetAddressfor the loopback address forfamily.Added in version 2.22.
- Parameters:
family – the address family
Methods#
- class InetAddress
-
- equal(other_address: InetAddress) bool#
Checks if two
InetAddressinstances are equal, e.g. the same address.Added in version 2.30.
- Parameters:
other_address – Another
InetAddress.
- get_family() SocketFamily#
Gets
address's familyAdded in version 2.22.
- get_is_any() bool#
Tests whether
addressis the “any” address for its family.Added in version 2.22.
- get_is_link_local() bool#
Tests whether
addressis a link-local address (that is, if it identifies a host on a local network that is not connected to the Internet).Added in version 2.22.
- get_is_loopback() bool#
Tests whether
addressis the loopback address for its family.Added in version 2.22.
- get_is_mc_global() bool#
Tests whether
addressis a global multicast address.Added in version 2.22.
- get_is_mc_link_local() bool#
Tests whether
addressis a link-local multicast address.Added in version 2.22.
- get_is_mc_node_local() bool#
Tests whether
addressis a node-local multicast address.Added in version 2.22.
- get_is_mc_org_local() bool#
Tests whether
addressis an organization-local multicast address.Added in version 2.22.
- get_is_mc_site_local() bool#
Tests whether
addressis a site-local multicast address.Added in version 2.22.
- get_is_site_local() bool#
Tests whether
addressis a site-local address such as 10.0.0.1 (that is, the address identifies a host on a local network that can not be reached directly from the Internet, but which may have outgoing Internet connectivity via a NAT or firewall).Added in version 2.22.
Properties#
- class InetAddress
-
- props.family: SocketFamily#
The address family (IPv4 or IPv6).
Added in version 2.22.
- props.flowinfo: int#
The flowinfo for an IPv6 address. See
get_flowinfo.Added in version 2.86.
- props.is_any: bool#
Whether this is the “any” address for its family. See
get_is_any().Added in version 2.22.
- props.is_link_local: bool#
Whether this is a link-local address. See
get_is_link_local().Added in version 2.22.
- props.is_loopback: bool#
Whether this is the loopback address for its family. See
get_is_loopback().Added in version 2.22.
- props.is_mc_global: bool#
Whether this is a global multicast address. See
get_is_mc_global().Added in version 2.22.
- props.is_mc_link_local: bool#
Whether this is a link-local multicast address. See
get_is_mc_link_local().Added in version 2.22.
- props.is_mc_node_local: bool#
Whether this is a node-local multicast address. See
get_is_mc_node_local().Added in version 2.22.
- props.is_mc_org_local: bool#
Whether this is an organization-local multicast address. See
get_is_mc_org_local().Added in version 2.22.
- props.is_mc_site_local: bool#
Whether this is a site-local multicast address. See
get_is_mc_site_local().Added in version 2.22.
- props.is_multicast: bool#
Whether this is a multicast address. See
get_is_multicast().Added in version 2.22.
- props.is_site_local: bool#
Whether this is a site-local address. See
get_is_loopback().Added in version 2.22.
- props.scope_id: int#
The scope-id for an IPv6 address. See
get_scope_id.Added in version 2.86.