>>>import namp
>>> nm = nmap.PortScanner()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/nmap/nmap.py", line 131, in __init__
os.getenv('PATH')
nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : /Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/lib/python2.7/site-packages/python_nmap-0.6.1-py2.7.egg:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/mysql/bin'
#'Nmap version 5.0 ( http://nmap.org )'
# This is for Mac OSX. When idle3 is launched from the finder, PATH is not set so nmap was not found
for nmap_path in nmap_search_path:
try:
if sys.platform.startswith('freebsd') \
or sys.platform.startswith('linux') \
or sys.platform.startswith('darwin'):
p = subprocess.Popen([nmap_path, '-V'],
bufsize=10000,
stdout=subprocess.PIPE,
close_fds=True)
else:
p = subprocess.Popen([nmap_path, '-V'],
bufsize=10000,
stdout=subprocess.PIPE)
except OSError:
pass
else:
self._nmap_path = nmap_path # save path
break
else:
raise PortScannerError(
'nmap program was not found in path. PATH is : {0}'.format(
os.getenv('PATH')
)
)
这个我试很多次才成功, 老是出现找不到资源的错误,
curl: (28) Operation timed out after 0 milliseconds with 0 out of 0 bytes received
Error: Failed to download resource "nmap"
可能是因为网络不行。
到此nmap安装已经安装好了。
但是执行: nmap 命令还是出现:
-bash: nmap: command not found
需要按照命令提示执行一下命令:
brew link --overwrite nmap
再执行namp -V , 成功!
安装nmap成功后命令行中有个警告:
==> Caveats
Python modules have been installed and Homebrew's site-packages is not
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run:
mkdir -p /Users/jason/Library/Python/2.7/lib/python/site-packages
echo 'import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")' >> /Users/jason/Library/Python/2.7/lib/python/site-packages/homebrew.pth
这个python modeles就是指python-nmap , 按照命令执行下:(我的python-nmap 是先于nmap安装好的,所以有这个提示。)