将参数传递给 Scapy 的 Automaton.run() 方法
Pass arguments to Scapy's Automaton.run() method
我正在尝试创建一个自动机来使用 Scapy 的自动机解析不同的数据包 class。
为此,我需要能够将数据包作为参数传递给自动机。
一种方法是在创建自动机时传递数据包:
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()
我正在尝试创建一个自动机来使用 Scapy 的自动机解析不同的数据包 class。
为此,我需要能够将数据包作为参数传递给自动机。 一种方法是在创建自动机时传递数据包:
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()