SnatTarget

class SnatTarget(*, addr: Optional[Union[IPv4Address, IPv6Address]] = None, port: Optional[int] = None, last_port: Optional[int] = None, is_random=False, is_fully_random=False, is_persistent=False)[source]

This class provides access to the SNAT target

Parameters:
  • addr – an IPv4Address or IPv6Address instance

  • port – port number (integer)

  • last_port – port number (integer) used when defining a port range

  • is_random – if True, use the iptables(8) --random option

  • is_fully_random – if True, use the iptables(8) --random-fully option

  • is_persistent – if True, use the iptables(8) --persistent option

is_fully_random() bool[source]

Returns True when fully random port mapping is enabled

set_fully_random() None[source]

Enable randomized port mapping

to_iptables_args() List[str][source]

Returns a list of iptables(8) arguments

get_address() Optional[Union[IPv4Address, IPv6Address]]

Returns the address used as the new source address (in the case of SNAT) or destination address (in the case DNAT).

get_ports() Tuple[Optional[int], Optional[int]]

Returns the port range used for NATing.

get_target_name() str

Returns the target name

is_persistent() bool

Returns True when persistent port mapping is enabled

is_random() bool

Returns True when random port mapping is enabled

is_terminating() bool

Returns True if this is a terminating target

set_address(addr: Union[IPv4Address, IPv6Address]) None

Set the address

set_persistent() None

Enable persistent port mapping

set_port(port: int) None

Set the port

set_port_range(port: int, last_port: int) None

Set the port range

set_random() None

Enable randomized port mapping