PacketMatch¶
Example:
>>> m = PacketMatch()
>>> m.input_interface().equals('eth0')
<linuxnet.iptables.match.PacketMatch object at 0x7ff96e466e10>
>>> m.fragment().not_equals()
<linuxnet.iptables.match.PacketMatch object at 0x7ff96e466e10>
>>> m.source_address().equals(IPv4Network('192.168.1.0/24'))
<linuxnet.iptables.match.PacketMatch object at 0x7ff96e466e10>
>>> m.to_iptables_args()
['-i', 'eth0', '!', '-f', '-s', '192.168.1.0/24']
- class PacketMatch[source]¶
This class provides matching against the following attributes of a packet:
input interface
output interface
protocol
source address
destination address
fragment bit
- protocol() ProtocolCriterion[source]¶
Match against the protocol
- input_interface() InputInterfaceCriterion[source]¶
Match against the input interface
- output_interface() OutputInterfaceCriterion[source]¶
Match against the output interface
- source_address() SourceAddressCriterion[source]¶
Match against the source address
- dest_address() DestAddressCriterion[source]¶
Match against the destination address
- fragment() FragmentCriterion[source]¶
Match if packet has (or has not) the fragment bit set
InputInterfaceCriterion¶
- class InputInterfaceCriterion(match: Match)[source]¶
Compare with the input interface.
The comparison value is an interface name (a string).
- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- get_iptables_option() str¶
Returns the iptables(8) option
- get_value() Any¶
Returns the criterion value
- 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
OutputInterfaceCriterion¶
- class OutputInterfaceCriterion(match: Match)[source]¶
Compare with the output interface.
The comparison value is an interface name (a string).
- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- get_iptables_option() str¶
Returns the iptables(8) option
- get_value() Any¶
Returns the criterion value
- 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
ProtocolCriterion¶
- class ProtocolCriterion(match: Match)[source]¶
Compare with the protocol.
The comparison value is a protocol name (a string).
- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- get_iptables_option() str¶
Returns the iptables(8) option
- get_value() Any¶
Returns the criterion value
- 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
SourceAddressCriterion¶
- class SourceAddressCriterion(match: Match)[source]¶
Compare with the source address.
The comparison value is an
IPv4Network.- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- get_iptables_option() str¶
Returns the iptables(8) option
- get_value() Any¶
Returns the criterion value
- 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
DestAddressCriterion¶
- class DestAddressCriterion(match: Match)[source]¶
Compare with the destination address.
The comparison value is an
IPv4Network.- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- get_iptables_option() str¶
Returns the iptables(8) option
- get_value() Any¶
Returns the criterion value
- 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
FragmentCriterion¶
- class FragmentCriterion(match: Match)[source]¶
Check if a packet is a fragment.
- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- get_value() bool¶
Returns the criterion value
- 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