Python 脚本中的 Scapy
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23269226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Scapy In A Script
提问by an earwig
I have used scapy as a session in python, but I want to use it in a script. Why so? I want to be able to use sys.argv
to specify an IP address to use as well as use other modules. How can this be accomplished?
我在 python 中使用了 scapy 作为会话,但我想在脚本中使用它。为什么这样?我希望能够用于sys.argv
指定要使用的 IP 地址以及使用其他模块。如何做到这一点?
采纳答案by Pierre
You just need to import it, as any other Python module.
你只需要像任何其他 Python 模块一样导入它。
from scapy.layers.inet import IP, ICMP
from scapy.sendrecv import sr
import sys
sr(IP(dst=sys.argv[1])/ICMP())
Or if you want to import everything at once:
或者,如果您想一次导入所有内容:
import scapy.all as scapy
import sys
scapy.sr(scapy.IP(dst=sys.argv[1])/scapy.ICMP())
[...]
Or if you want to code exactly as in the Scapy console:
或者,如果您想完全按照 Scapy 控制台中的编码进行编码:
from scapy.all import *
import sys
sr(IP(dst=sys.argv[1])/ICMP())