简体   繁体   English

如何指定一个scapy启动文件?

[英]How to specify a scapy startup file?

I use scapy with the -c command line option to load a startup file:我使用带有 -c 命令行选项的 scapy 来加载启动文件:

# liquidsoap debug
streamerIP = "192.168.0.53"
dump= []

def filterStreamer(pkt):
    if pkt.src == streamerIP or pkt.dst == streamerIP:
        dump.append(pkt)

sniff(prn=filterStreamer)

ls(dump)

it gives:它给:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/scapy/main.py", line 30, in _read_config_file
    execfile(cf)
  File "icecast-debug.py", line 9, in <module>
    sniff(prn=filterStreamer)
  File "/usr/lib/python2.7/dist-packages/scapy/sendrecv.py", line 586, in sniff
    r = prn(p)
  File "icecast-debug.py", line 6, in filterStreamer
    if (pkt.src == streamerIP or pkt.dst == streamerIP):
NameError: global name 'streamerIP' is not defined
Welcome to Scapy (2.2.0)

and in the console I see nor the streamerIP neither dump, but funniest of all filterStreamer as a function are not defined.在控制台中,我看到的 streamerIP 也没有转储,但最有趣的是 filterStreamer 作为函数没有定义。 However if I do not pass filterStreamer to sniff it begins sniffing.但是,如果我不通过 filterStreamer 进行嗅探,它就会开始嗅探。 So it's like interpreting the code line by line, and clear the scope after all line interpretition.所以就像一行一行的解释代码,在所有的行解释之后清除范围。

You have to use the global keyword.您必须使用global关键字。 Also, use a PacketList() rather than a list.此外,使用PacketList()而不是列表。 And ls() will not work against a list, but if you use a PacketList() , you have the .summary() method.并且ls()不适用于列表,但如果您使用PacketList() ,则您拥有.summary()方法。

streamerIP = "192.168.0.53"
dump = PacketList()

def filterStreamer(pkt):
    global streamerIP, dump
    if pkt.src == streamerIP or pkt.dst == streamerIP:
        dump.append(pkt)

dump.summary()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM