- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 pyinstaller 从我用于测试的脚本创建简单的可执行文件,这样我就不必在我正在测试的服务器上安装所有东西。
#! /usr/bin/env python
from scapy.all import *
sourceport=int(raw_input('Soruce port:'))
destinationport=int(raw_input('Destination port:'))
destinationip=raw_input('Destination IP:')
maxttl=int(raw_input('MAX TTL:'))
for i in range(1,maxttl):
udptrace = IP(dst=destinationip,ttl=i)/UDP(dport=destinationport,sport=sourceport,len=500)
received=sr1(udptrace,verbose=0,timeout=2)
try:
print received.summary()
except AttributeError:
print "** TIMEOUT **"
然后我制作可执行文件:
pyinstaller -F udp.py
但是当我运行它时出现以下错误:
Soruce port:500
Destination port:500
Destination IP:4.4.4.4
MAX TTL:3
Traceback (most recent call last):
File "<string>", line 16, in <module>
NameError: name 'IP' is not defined
user@:~/2/dist$
我花了一些时间研究但没有找到任何答案。
最佳答案
首先,我们需要查明确切的问题。
PyInstaller 手册 specifies那:
Some Python scripts import modules in ways that PyInstaller cannot detect: for example, by using the
__import__()
function with variable data.
检查 Scapy's source code表明这正是各种网络层的导入方式:
scapy/layers/all.py
:
def _import_star(m):
mod = __import__(m, globals(), locals())
for k,v in mod.__dict__.iteritems():
globals()[k] = v
for _l in conf.load_layers:
log_loading.debug("Loading layer %s" % _l)
try:
_import_star(_l)
except Exception,e:
log.warning("can't import layer %s: %s" % (_l,e))
请注意 __import__
为 conf.load_layers
中的每个模块调用.
scapy/config.py
:
class Conf(ConfClass):
"""This object contains the configuration of scapy."""
load_layers = ["l2", "inet", "dhcp", "dns", "dot11", "gprs", "hsrp", "inet6", "ir", "isakmp", "l2tp",
"mgcp", "mobileip", "netbios", "netflow", "ntp", "ppp", "radius", "rip", "rtp",
"sebek", "skinny", "smb", "snmp", "tftp", "x509", "bluetooth", "dhcp6", "llmnr", "sctp", "vrrp",
"ipsec" ]
请注意 Conf.load_layers
包含 "inet"
.
文件 scapy/layers/inet.py
定义 IP
类,在随附的示例中未成功导入。
现在,我们已经找到了根本原因,让我们看看可以采取什么措施。
PyInstaller 手册 suggests此类导入问题的一些解决方法:
- You can give additional files on the PyInstaller command line.
- You can give additional import paths on the command line.
- You can edit the
myscript.spec
file that PyInstaller writes the first time you run it for your script. In the spec file you can tell PyInstaller about code and data files that are unique to your script.- You can write "hook" files that inform PyInstaller of hidden imports. If you "hook" imports for a package that other users might also use, you can contribute your hook file to PyInstaller.
谷歌搜索显示一个适当的“钩子(Hook)”已经被添加到默认的 PyInstaller 发行版中,在这个 commit 中,其中介绍了文件 PyInstaller/hooks/hook-scapy.layers.all.py
.
PyInstaller 手册 indicates这样的内置 Hook 应该自动运行:
In summary, a "hook" file tells PyInstaller about hidden imports called by a particular module. The name of the hook file is
hook-<module>.py
where "<module>
" is the name of a script or imported module that will be found by Analysis. You should browse through the existing hooks in the hooks folder of the PyInstaller distribution folder, if only to see the names of the many supported imports.For example
hook-cPickle.py
is a hook file telling about hidden imports used by the modulecPickle
. When your script hasimport cPickle
the Analysis will note it and check for a hook filehook-cPickle.py
.
因此,请确认您运行的是最新版本的 PyInstaller。如果您无法升级到最新版本,或者它不包含文件 PyInstaller/hooks/hook-scapy.layers.all.py
, 然后用 following content 创建它:
#-----------------------------------------------------------------------------
# Copyright (c) 2013, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License with exception
# for distributing bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
from PyInstaller.hooks.hookutils import collect_submodules
# The layers to load can be configured using scapy's conf.load_layers.
# from scapy.config import conf; print(conf.load_layers)
# I decided not to use this, but to include all layer modules. The
# reason is: When building the package, load_layers may not include
# all the layer modules the program will use later.
hiddenimports = collect_submodules('scapy.layers')
关于Python Scapy 和 Pyinstaller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30413305/
我使用 Scapy 创建一个初始 OpenVPN 数据包并将其发送到 OpenVPN 服务器(作为客户端)。数据包的 OpenVPN 部分我只是从旧的捕获连接中重用,但它在这里无关紧要。 事情是,我添
我在使用 Scapy 进行 TCP 握手时遇到问题。我的 Scapy 代码正在发送 SYN 数据包。目标正在使用 SYN/ACK 数据包进行响应。我可以在 tcpdump 中看到 SYN/ACK 数据
我正在查看一个需要制作 S1 应用程序协议(protocol) (S1AP) 数据包的项目。它用于 4G LTE 网络的 eNodeB 和 MME 之间。 S1AP 基于 IP 并由 Steam 控制
我尝试导入 scapy.all,但出现“wpcap.dll”不存在的错误。为什么会这样?我确定我正确下载了所有内容。我将所有内容保存到一个名为 scapy 的文件夹中。我从模块 ctypes 得到了一
如果我生成一个没有任何上层有效载荷的以太网帧并使用 sendp() 在第二层发送它,那么我会收到 "Mac address to reach destination not found. Using
I'm new to scapy and I'm trying to implement a protocol.Within this protocol a type, lets call it
我在 Windows 7 和 Fedora 机器上都安装了 scapy。但是,contrib 包没有安装(或者至少,它没有出现在我的 site-packages/scapy 包下。我怎样才能安装它?
我只是想在scapy中创建一个以eg开头的数据包 数据包 = RadioTap()/Dot11()/Dot11ACK() packet.show() 给了我这个错误。我无法发送任何没有 RadioTa
如何使用 scapy 创建一组具有递增有效负载的数据包?例如,第一个数据包的有效负载(数据)必须为 1,第二个必须为 2,依此类推。 我试过这个: >>> pkt=(Ether(dst='00:01:
我想知道如何验证从Scapy的sr1()函数接收到的数据包包含TCP层,以便对TCP标志进行一些处理。 最佳答案 您有两个选择,in运算符是一个。 >>> TCP in pkt True >>> if
我正在尝试使用Scapy学习一些数据包生成。看起来很酷。根据一些文档,我正在这样做: l3=IP(dst="192.168.0.1", src="192.168.0.2", tos=(46 ", li
我需要发送格式错误的以太网帧以进行测试。我已禁用 Rx 和 Tx 校验和的卸载: root@T60:~# ethtool --show-offload eth0 Features for eth0:
如何使用 scapy 更改数据包数据? 我尝试使用sniff(),然后send()编辑的数据包,但它不起作用,因为原始数据包已经到达目的地。 最佳答案 “但是它不会工作,因为原始数据包已经到达目的地。
我在 Ubuntu 16.04 中运行 sacpy 2.4。我发现基本数据包(Eth/IP/UDP 或 Eth/IP/TCP)wireshark 经常标记失败的帧检查序列。 经过调查,我发现“损坏的数
Scapy 文档给出了以下 ARP 缓存中毒的例子: send(Ether(dst=clientMAC)/ARP(op="who-has", psrc=gateway, pdst=client)) 问
背景: 我正在使用 scapy 测试一个网络设备,该设备可以通过交换源/目标 MAC、IP 地址和第 4 层端口号来选择性地环回数据包。可以为 layer_2_only 选择交换, layers_2_
如果我使用 sr1 为 www.google.com 发送 DNSQR,我会收到几个 DNSRR(s) 作为回复,例如(使用 ans[DNSRR].show() 完成): ###[ DNS Resou
我想将我的数据包发送到一个 UDP dst 端口号并通过 eth0 接口(interface)发送(如果 scapy 直接处理我的 layer2,那么 eth0 不需要作为参数给出) 最佳答案 使用
我如何计算我使用的捕获的数据包数量 packets = sniff(filter='udp and host fe80::xx:xx:xx:xx',count=0) 功能?这可能吗? 我实际上一直在尝
我正在使用 F5 Networks Big-IP 产品,该产品附加了一个自定义以太网 II 尾帧以进行调试。我正在尝试使用 Scapy 为这个预告片绑定(bind)一个新图层,但我无法这样做。 我可以
我是一名优秀的程序员,十分优秀!