ndiff - PYTHONPATH 环境变量

ndiff - PYTHONPATH environment variable

我的 Ndiff 有问题,我无法执行它。 (Nmap 完美运行)

所以我尝试使用 ndiff 并收到此错误消息:

Could not import the ndiff module: 'No module named ndiff'.

I checked in these directories:

/usr/local/bin
/usr/local/bin
/usr/local/bin/ndiff
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC
/Library/Python/2.7/site-packages

If you installed Ndiff in another directory, you may have to add the
modules directory to the PYTHONPATH environment variable.

于是我搜索了ndiff的路径,导出到PYTHONPATH中。但它不起作用,我做错了什么?

which ndiff
/usr/local/bin/ndiff

我用自制软件重新安装了 ndiff 和 nmap,并且知道我在尝试执行此代码后收到此消息

$ ndiff firstScan.xml secondScann.xml > diffScan

Traceback (most recent call last):
  File "/usr/local/bin/ndiff", line 84, in <module>
    sys.excepthook = ndiff.excepthook
AttributeError: 'module' object has no attribute 'excepthook'

您尝试 运行 /usr/local/bin/ndiff 的命令是伪装的 Python 脚本(也就是说,它没有 .py 扩展名) .

在该脚本顶部的某处,它尝试导入 ndiff 模块本身:

import ndiff

其中,看到路径/usr/local/,可能安装在/usr/local/lib/python2.7/site-packages/(*)。您需要将此路径添加到 PYTHONPATH:

export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python2.7/site-packages

现在,脚本可以拾取模块,愉快地继续。

(*) 它可能安装在其他地方,在这种情况下,您必须手动找到它。您可以尝试 find /usr/local -name ndiff.py 之类的东西来查看它的安装位置。


第二个错误,在您重新安装后,可能是由于您当前工作目录中某处的 ndiff.py 松动引起的。在这种情况下,/usr/local/bin/ndiff 将尝试导入该文件,并认为它是实际的 ndiff 模块。因为它不是,所以当它试图访问某些模块属性时会失败,例如 ndiff.excepthook,松散的 ndiff.py 没有。删除松散的文件,你应该可以开始了。

可能没有必要更改 PYTHONPTH 环境变量,发生的情况是 ndiff 脚本指向错误的路径或 wrong/non-existent 文件。 只需编辑可能位于 /usr/bin/ndiff:

中的 ndiff 脚本(作为二进制文件传递)
# sudo vi /usr/bin/ndiff

并找到行:INSTALL_LIB = '...

它应该读取 python 站点包目录的完整路径,例如: INSTALL_LIB = '/usr/lib/python2.7/site-packages'

在其中寻找名为 ndiff.py 的文件:

# sudo find /usr/lib/python2.7/site-packages -name ndiff.py

如果存在 none,您必须创建它并将此处存在的所有内容粘贴到其中:https://raw.githubusercontent.com/nmap/nmap/master/ndiff/ndiff.py

到时候应该都可以了。