scapy.automaton

Automata with states, transitions and actions.

class scapy.automaton.ATMT[source]

Bases: object

ACTION = 'Action'
CONDITION = 'Condition'
IOEVENT = 'I/O event'
exception NewStateRequested(state_func: Any, automaton: ATMT, *args: Any, **kargs: Any)[source]

Bases: Exception

action_parameters(*args: Any, **kargs: Any) NewStateRequested[source]
run() Any[source]
RECV = 'Receive condition'
STATE = 'State'
TIMEOUT = 'Timeout condition'
static action(cond: Any, prio: int = 0) Callable[[_StateWrapper, _StateWrapper], _StateWrapper][source]
static condition(state: Any, prio: int = 0) Callable[[_StateWrapper, _StateWrapper], _StateWrapper][source]
static ioevent(state: _StateWrapper, name: str, prio: int = 0, as_supersocket: Optional[str] = None) Callable[[_StateWrapper, _StateWrapper], _StateWrapper][source]
static receive_condition(state: _StateWrapper, prio: int = 0) Callable[[_StateWrapper, _StateWrapper], _StateWrapper][source]
static state(initial: int = 0, final: int = 0, stop: int = 0, error: int = 0) Callable[[DecoratorCallable], DecoratorCallable][source]
static timeout(state: _StateWrapper, timeout: Union[int, float]) Callable[[_StateWrapper, _StateWrapper, Timer], _StateWrapper][source]
static timer(state: _StateWrapper, timeout: Union[float, int], prio: int = 0) Callable[[_StateWrapper, _StateWrapper, Timer], _StateWrapper][source]
class scapy.automaton.Automaton(self, debug=0, store=1, **kargs)[source]

Bases: object

exception AutomatonError(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: AutomatonException

exception AutomatonException(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: Exception

exception AutomatonStopped(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: AutomatonException

exception Breakpoint(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: AutomatonStopped

exception CommandMessage(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: AutomatonException

exception ErrorState(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: AutomatonException

exception InterceptionPoint(msg: str, state: Optional[Message] = None, result: Optional[str] = None, packet: Optional[str] = None)[source]

Bases: AutomatonStopped

exception Singlestep(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: AutomatonStopped

exception Stuck(msg: str, state: Optional[Message] = None, result: Optional[str] = None)[source]

Bases: AutomatonException

accept_packet(pkt: Optional[Packet] = None, wait: Optional[bool] = False) Any[source]
actions: Dict[str, List[_StateWrapper]] = {}
add_breakpoints(*bps: Any) None[source]
add_interception_points(*ipts: Any) None[source]
conditions: Dict[str, List[_StateWrapper]] = {}
debug(lvl: int, msg: str) None[source]
forcestop(wait: bool = True) None[source]
initial_states: List[_StateWrapper] = []
ioevents: Dict[str, List[_StateWrapper]] = {}
ionames: List[str] = []
iosupersockets: List[SuperSocket] = []
master_filter(pkt: Packet) bool[source]
my_send(pkt: Packet) None[source]
next() Any[source]
parse_args(debug: int = 0, store: int = 1, **kargs: Any) None[source]
recv_conditions: Dict[str, List[_StateWrapper]] = {}
reject_packet(wait: Optional[bool] = False) Any[source]
remove_breakpoints(*bps: Any) None[source]
remove_interception_points(*ipts: Any) None[source]
restart(*args: Any, **kargs: Any) None[source]
run(resume: Optional[Message] = None, wait: Optional[bool] = True) Any[source]
runbg(resume: Optional[Message] = None, wait: Optional[bool] = False) None[source]
send(pkt: Packet) None[source]
start(*args: Any, **kargs: Any) None[source]
state: NewStateRequested = None
states: Dict[str, _StateWrapper] = {}
stop(wait: bool = True) None[source]
stop_states: List[_StateWrapper] = []
timeout: Dict[str, _TimerList] = {}
timer_by_name(name: str) Optional[Timer][source]
class scapy.automaton.Automaton_metaclass(name: str, bases: Tuple[Any], dct: Dict[str, Any])[source]

Bases: type

build_graph() str[source]
graph(**kargs: Any) Optional[str][source]
class scapy.automaton.Message(**args: Any)[source]

Bases: object

exc_info: Union[Tuple[None, None, None], Tuple[BaseException, Exception, TracebackType]] = None
pkt: Packet = None
result: str = None
state: Message = None
type: str = None
class scapy.automaton.ObjectPipe(name: Optional[str] = None)[source]

Bases: Generic[_T]

clear() None[source]
close() None[source]
empty() bool[source]
fileno() int[source]
flush() None[source]
read(n: Optional[int] = 0) Optional[_T][source]
recv(n: Optional[int] = 0) Optional[_T][source]
static select(sockets: List[SuperSocket], remain: Optional[float] = 0.05) List[SuperSocket][source]
send(obj: _T) int[source]
write(obj: _T) None[source]
class scapy.automaton.Timer(time: Union[int, float], prio: int = 0, autoreload: bool = False)[source]

Bases: object

get() float[source]
set(val: float) None[source]
scapy.automaton.select_objects(inputs: Iterable[Any], remain: Optional[Union[float, int]]) List[Any][source]

Select objects. Same than: select.select(inputs, [], [], remain)

But also works on Windows, only on objects whose fileno() returns a Windows event. For simplicity, just use ObjectPipe() as a queue that you can select on whatever the platform is.

If you want an object to be always included in the output of select_objects (i.e. it’s not selectable), just make fileno() return a strictly negative value.

Example

>>> a, b = ObjectPipe("a"), ObjectPipe("b")
>>> b.send("test")
>>> select_objects([a, b], 1)
[b]
Parameters
  • inputs – objects to process

  • remain – timeout. If 0, return [].