IcmpMatch

Example:

>>> from linuxnet.iptables import IcmpMatch
>>> m = IcmpMatch()
>>> m.icmp_type().equals('host-unreachable')
<linuxnet.iptables.matches.icmpmatch.IcmpMatch object at 0x7fc9b5cab240>
>>> m.to_iptables_args()
['-m', 'icmp', '--icmp-type', 'host-unreachable']
>>> m1 = IcmpMatch()
>>> m1.icmp_type().equals(icmp_type_value=3, icmp_code=1)
<linuxnet.iptables.matches.icmpmatch.IcmpMatch object at 0x7fc9b5cab278>
>>> m1.to_iptables_args()
['-m', 'icmp', '--icmp-type', 'host-unreachable']
>>> m2 = IcmpMatch()
>>> m2.icmp_type().equals(icmp_type_value=3, icmp_code=8)
<linuxnet.iptables.matches.icmpmatch.IcmpMatch object at 0x7fc9b5cab550>
>>> m2.to_iptables_args()
['-m', 'icmp', '--icmp-type', '3/8']
class IcmpMatch[source]

Match against the fields of the ICMP header

icmp_type() IcmpTypeCriterion[source]

Criterion for matching against the ICMP type

to_iptables_args() List[str][source]

Returns iptables(8) arguments for this match


IcmpTypeCriterion

class IcmpTypeCriterion(match: Match)[source]

Compare with the ICMP type.

The comparison value is the tuple (icmp-type-name, icmp-type-value, icmp-code); icmp-type-name is a string, icmp-type-value is an integer, and icmp-code is an integer. icmp-type-name and icmp-code may be None.

See iptables(8) for a list valid icmp-type-name values.

get_type_name() Optional[str][source]

Returns the ICMP type name

get_type_value() int[source]

Returns the ICMP type value

get_code() Optional[int][source]

Returns the ICMP code

get_value() Tuple[Optional[str], int, Optional[int]][source]

Returns the value that the criterion is comparing against. This is a tuple (icmp_type_name, icmp_type_value, icmp_code); icmp_type_value is an integer. icmp_type_name is a string and may be None. icmp_code is an integer and may be None.

equals(icmp_type_name: Optional[str] = None, icmp_type_value: Optional[int] = None, icmp_code: Optional[int] = None) Match[source]

Check for equality against the specified ICMP type name or value; one of the two must be present.

Parameters:
  • icmp_type_name – a string from one of the values accepted by iptables(8)

  • icmp_type_value – an integer specifiying the particular ICMP type value; the special value -1 maps to the type any.

  • icmp_code – an optional integer specifying a particular code for the ICMP type; this parameter may be used with the icmp_type_value parameter

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.