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
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_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_valueis an integer.icmp_type_nameis a string and may beNone.icmp_codeis an integer and may beNone.
- 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
-1maps 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_valueparameter
- any() Match¶
Match any value.
This method is used when creating a
Criterionin 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()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- is_positive() bool¶
Returns the ‘polarity’ of the criterion:
Trueforequals()orFalsefornot_equals()Raises
IptablesErrorif the criterion is not set
- is_set() bool¶
Returns
Trueif the criterion has been set