我想创建一个自动解析与Scapy的的自动机类不同的数据包。
为了做到这一点,我需要能够将数据包作为参数传递给自动机。这样做的一个方法是在创建时自动传递数据包:
my_automaton = MyAutomaton(packet)
这一论点在自动机代码重载parse_args
函数来处理:
class MyAutomaton(Automaton):
def parse_args(self, pkt, **kargs):
Automaton.parse_args(self, **kargs)
self.pkt = pkt
... REST OF CLASS ...
如果我为每一个传入包一个新的自动机这很好地工作。
但是,我想只能创建一个自动机,并用不同的数据包运行它。就像是:
my_automaton = MyAutomaton()
my_automaton.run(pkt1)
my_automaton.run(pkt2)
根据文档,这应该是可能的(link):
The parse_args() method is called with arguments given at __init__() and run(). Use that to parametrize the behaviour of your automaton.
并打印到控制台当parse_args
方法被调用我核实,这的确是叫在自动创建并在run
方法被调用。
但我似乎并没有能够通过run
函数传递任何说法,我缺少什么吗?
作为对文档显示,你需要传递的参数在初始化自动机:
>>> TFTP_read("my_file", "192.168.1.128").run()
你的情况,这将是
my_automaton = MyAutomaton(pkt1)
my_automaton.run()
my_automaton2 = MyAutomaton(pkt2)
my_automaton2.run()