-1

I have a problem with Ndiff, I can't execute it. (Nmap works perfect)

So I try to use ndiff and get this error message:

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.

So I search for the path of ndiff and export it to PYTHONPATH. But it doesn't work out, what I am doing wrong?

which ndiff
/usr/local/bin/ndiff

I re-install ndiff and nmap with homebrew and know I get this message, after I try to execute this code

$ 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'
Loretta
  • 154
  • 15
  • know I have this problem: usr/bin/awk: can't open file ./share/lib/ndiff/ndiff-2.00/ndiff.awk source line number 1 source file ./share/lib/ndiff/ndiff-2.00/ndiff.awk context is >>> << – Loretta Jan 06 '15 at 14:16
  • ndiff firstScan.xml secondScann.xml > diffScan is this one – Loretta Jan 06 '15 at 14:44
  • Most likely, your `PYTHONPATH` needs to include `/usr/local/lib/python2.7/site-packages` (you can see it's not searched for, thus not included). `ndiff` is probably just wrapper program around a Python module, and without the correct `PYTHONPATH`, it can't found that module. –  Jan 06 '15 at 14:47
  • Btw, don't use the symlink @PadraicCunningham suggests; it doesn't help, except for convoluting things. I think this is causing the second error, since `/usr/local/bin/ndiff` will now see an `ndiff.py` file in your current directory as the ndiff module (which, of course, it is not). If you have that `ndiff.py` file, remove it. –  Jan 06 '15 at 14:51
  • @Evert, so `Could not import the ndiff module: 'No module named ndiff'.` comes from bash yes? – Padraic Cunningham Jan 06 '15 at 15:03
  • @PadraicCunningham No, because the `ndiff` command is a Python script without the `.py` extension, which apparently tries to import a module called `ndiff`. Once it fails that, it issues the help text "I checked in these directories: .... If you installed Ndiff in another directory, you may have to add the modules directory to the PYTHONPATH environment variable." –  Jan 06 '15 at 15:08
  • For the record, here is that ndiff script: https://svn.nmap.org/nmap/ndiff/scripts/ndiff –  Jan 06 '15 at 15:08
  • @PadraicCunningham Probably the ndiff version you're looking at is an older version; I have an older version on my system as well. In a newer version, they moved most of the code into a separate module. Compare [this older version](https://svn.nmap.org/nmap/ndiff/ndiff?p=32000) to [this newer version](https://svn.nmap.org/nmap/ndiff/scripts/ndiff). The latter, newer version, also explains the last error the OP saw: the line `sys.excepthook = ndiff.excepthook` exists in the newer script, not in the older script. There's also a note in the nmap changelog on this for nmap version 6.47. –  Jan 06 '15 at 15:21
  • Also: https://github.com/nmap/nmap/commit/1e6db2b22c5c5ebe44e9974e8c794c7804089383 makes it more clear that things changed recently. –  Jan 06 '15 at 15:51
  • first - sry for my late response and thanks for the help :) – Loretta Jan 13 '15 at 10:53

2 Answers2

0

The command you're trying to run /usr/local/bin/ndiff, is a Python script in disguise (that is, it doesn't have the .py extension).

Somewhere at the top of that script, it tries to import the ndiff module itself:

import ndiff

which, seen the path /usr/local/, is probably installed in /usr/local/lib/python2.7/site-packages/(*). You need to add this path to your PYTHONPATH:

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

Now, the script can pick up the module, and happily continue.

(*) it may get installed somewhere else, in which case you'll have to locate it manually. You could try something like find /usr/local -name ndiff.py to see where it is installed.


The second error, after your re-install, could be caused by a loose ndiff.py somewhere in your current working directory. In that case, /usr/local/bin/ndiff will try to import that file, and think it's the actual ndiff module. Since it's not, it will fail when it tries to access some of the modules attributes like ndiff.excepthook, which that loose ndiff.py doesn't have. Remove the loose file and you should be good to go.

  • perfect :) it works :) thank you so much. the file was in python2.6 – Loretta Jan 13 '15 at 10:54
  • @Loretta You mean inside the `/usr/local/lib/python2.6/site-packages/`? Because that seems a bit odd, given that the error messages in your question show Python 2.7 there. If it works, don't change it, but at some point, you may consider to do `brew update` and then `brew upgrade`. –  Jan 13 '15 at 12:32
  • yes, I mean this. no error messages it works perfect. And thanks for the advice – Loretta Jan 15 '15 at 11:57
0

It's probably not necessary to change the PYTHONPTH environment variable, what happens is that the ndiff script is pointing either to a wrong path or to a wrong/non-existent file. Just edit the ndiff script (passed as a binary) located likely in /usr/bin/ndiff:

# sudo vi /usr/bin/ndiff

and locate the line: INSTALL_LIB = '...

It should read the full path to your python site-packages directory, for example: INSTALL_LIB = '/usr/lib/python2.7/site-packages'

Seek for a file named ndiff.py in there:

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

If there is none present, you must create it and paste all the content present here in it: https://raw.githubusercontent.com/nmap/nmap/master/ndiff/ndiff.py

It should all work then.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Klawfinger
  • 29
  • 4