Skip to content

Gio.InetAddress

class — extends GObject.Object

GInetAddress represents an IPv4 or IPv6 internet address. Use Resolver.lookup_by_name or Resolver.lookup_by_name_async to look up the GInetAddress for a hostname. Use Resolver.lookup_by_address or Resolver.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

new_any

@classmethod
def new_any(cls, family: SocketFamily | int) -> InetAddress

Creates a InetAddress for the "any" address (unassigned/"don't care") for family.

Parameters:

  • family — the address family

new_from_bytes

@classmethod
def new_from_bytes(cls, bytes: list[int], family: SocketFamily | int) -> InetAddress

Creates a new InetAddress from the given family and bytes. bytes should be 4 bytes for SocketFamily.IPV4 and 16 bytes for SocketFamily.IPV6.

Parameters:

  • bytes — raw address data
  • family — the address family of bytes

new_from_bytes_with_ipv6_info

@classmethod
def new_from_bytes_with_ipv6_info(cls, bytes: list[int], family: SocketFamily | int, flowinfo: int, scope_id: int) -> InetAddress

Creates a new InetAddress from the given family, bytes and scope_id.

bytes must be 4 bytes for SocketFamily.IPV4 and 16 bytes for SocketFamily.IPV6.

Parameters:

  • bytes — raw address data
  • family — the address family of bytes
  • scope_id — the scope-id of the address

new_from_string

@classmethod
def new_from_string(cls, string: str) -> InetAddress | None

Parses string as an IP address and creates a new InetAddress.

If address is 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.

Parameters:

  • string — a string representation of an IP address

new_loopback

@classmethod
def new_loopback(cls, family: SocketFamily | int) -> InetAddress

Creates a InetAddress for the loopback address for family.

Parameters:

  • family — the address family

Methods

equal

def equal(self, other_address: InetAddress) -> bool

Checks if two InetAddress instances are equal, e.g. the same address.

Parameters:

get_family

def get_family(self) -> SocketFamily

Gets address's family

get_flowinfo

def get_flowinfo(self) -> int

Gets the value of InetAddress.flowinfo.

get_is_any

def get_is_any(self) -> bool

Tests whether address is the "any" address for its family.

def get_is_link_local(self) -> bool

Tests whether address is a link-local address (that is, if it identifies a host on a local network that is not connected to the Internet).

get_is_loopback

def get_is_loopback(self) -> bool

Tests whether address is the loopback address for its family.

get_is_mc_global

def get_is_mc_global(self) -> bool

Tests whether address is a global multicast address.

def get_is_mc_link_local(self) -> bool

Tests whether address is a link-local multicast address.

get_is_mc_node_local

def get_is_mc_node_local(self) -> bool

Tests whether address is a node-local multicast address.

get_is_mc_org_local

def get_is_mc_org_local(self) -> bool

Tests whether address is an organization-local multicast address.

get_is_mc_site_local

def get_is_mc_site_local(self) -> bool

Tests whether address is a site-local multicast address.

get_is_multicast

def get_is_multicast(self) -> bool

Tests whether address is a multicast address.

get_is_site_local

def get_is_site_local(self) -> bool

Tests whether address is 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).

get_native_size

def get_native_size(self) -> int

Gets the size of the native raw binary address for address. This is the size of the data that you get from g_inet_address_to_bytes().

get_scope_id

def get_scope_id(self) -> int

Gets the value of InetAddress.scope-id.

to_string

def to_string(self) -> str

Converts address to string form.

Virtual methods

do_to_string

def do_to_string(self) -> str

Converts address to string form.

Properties

bytes

bytes: int  # read/write

The raw address data.

family

family: SocketFamily | int  # read/write

The address family (IPv4 or IPv6).

flowinfo

flowinfo: int  # read/write

The flowinfo for an IPv6 address. See InetAddress.get_flowinfo.

is_any

is_any: bool  # read-only

Whether this is the "any" address for its family. See InetAddress.get_is_any.

is_link_local: bool  # read-only

Whether this is a link-local address. See InetAddress.get_is_link_local.

is_loopback

is_loopback: bool  # read-only

Whether this is the loopback address for its family. See InetAddress.get_is_loopback.

is_mc_global

is_mc_global: bool  # read-only

Whether this is a global multicast address. See InetAddress.get_is_mc_global.

is_mc_link_local: bool  # read-only

Whether this is a link-local multicast address. See InetAddress.get_is_mc_link_local.

is_mc_node_local

is_mc_node_local: bool  # read-only

Whether this is a node-local multicast address. See InetAddress.get_is_mc_node_local.

is_mc_org_local

is_mc_org_local: bool  # read-only

Whether this is an organization-local multicast address. See InetAddress.get_is_mc_org_local.

is_mc_site_local

is_mc_site_local: bool  # read-only

Whether this is a site-local multicast address. See InetAddress.get_is_mc_site_local.

is_multicast

is_multicast: bool  # read-only

Whether this is a multicast address. See InetAddress.get_is_multicast.

is_site_local

is_site_local: bool  # read-only

Whether this is a site-local address. See InetAddress.get_is_loopback.

scope_id

scope_id: int  # read/write

The scope-id for an IPv6 address. See InetAddress.get_scope_id.