Skip to content

Gio.InetAddressMask

class — extends GObject.Object, Initable

GInetAddressMask represents a range of IPv4 or IPv6 addresses described by a base address and a length indicating how many bits of the base address are relevant for matching purposes. These are often given in string form. For example, 10.0.0.0/8, or fe80::/10.

Constructors

new

@classmethod
def new(cls, addr: InetAddress, length: int) -> InetAddressMask

Creates a new InetAddressMask representing all addresses whose first length bits match addr.

Parameters:

  • addr — a InetAddress
  • length — number of bits of addr to use

new_from_string

@classmethod
def new_from_string(cls, mask_string: str) -> InetAddressMask

Parses mask_string as an IP address and (optional) length, and creates a new InetAddressMask. The length, if present, is delimited by a "/". If it is not present, then the length is assumed to be the full length of the address.

Parameters:

  • mask_string — an IP address or address/length string

Methods

equal

def equal(self, mask2: InetAddressMask) -> bool

Tests if mask and mask2 are the same mask.

Parameters:

get_address

def get_address(self) -> InetAddress

Gets mask's base address

get_family

def get_family(self) -> SocketFamily

Gets the SocketFamily of mask's address

get_length

def get_length(self) -> int

Gets mask's length

matches

def matches(self, address: InetAddress) -> bool

Tests if address falls within the range described by mask.

Parameters:

to_string

def to_string(self) -> str

Converts mask back to its corresponding string form.

Properties

address

address: InetAddress  # read/write

The base address.

family

family: SocketFamily | int  # read-only

The address family (IPv4 or IPv6).

length

length: int  # read/write

The prefix length, in bytes.