MultiportMatch

The MultiportMatch class provides access to the multiport match extension.

Example:

>>> from linuxnet.iptables import MultiportMatch
>>> m = MultiportMatch()
>>> m.source_ports().equals((80, 443, (8080,8089)))
<linuxnet.iptables.matches.multiportmatch.MultiportMatch object at 0x7f4f773d4e20>
>>> m.to_iptables_args()
['-m', 'multiport', '--source-ports', '80,443,8080:8089']
class MultiportMatch[source]

Match against sets of TCP/UDP ports.

static get_match_name() str[source]

Returns the iptables(8) match extension name

get_criteria() Iterable[Criterion][source]

Returns the multiport match criteria: source-ports, dest-ports, ports

source_ports() PortsCriterion[source]

Criterion with source ports to compare against

dest_ports() PortsCriterion[source]

Criterion with destination ports to compare against

ports() PortsCriterion[source]

Criterion with ports to compare against


PortsCriterion

class PortsCriterion(match: Match, iptables_option: str)[source]

Compare against a set of ports.

The value is a tuple; each element of the tuple is either a port number, or a tuple indicating a port range, e.g. (80, 443, (1024, 65536))

get_value()[source]

Returns the ports and ranges to compare against

equals(value: Iterable)[source]

Compare against a list of ports specified by value

any() Match

Match any value.

This method is used when creating a Criterion in order to search an existing chain for rules that try to match against certain packet properties (e.g. input interface) without being particular about the specific property value (e.g. eth0).

compare(is_equal: bool, *args, **kwargs) Match

Alternative method used for comparisons. It invokes equals() (or not_equals()) with args and kwargs if is_equal is True (or False).

is_positive() bool

Returns the ‘polarity’ of the criterion: True for equals() or False for not_equals()

Raises IptablesError if the criterion is not set

is_set() bool

Returns True if the criterion has been set

not_equals(*args, **kwargs) Match

Express inequality comparison against the argument values.

The arguments of this method are the same as those of the equals() method.

This method invokes the equals() method and then reverses the polarity.

Returns this Match object.