请叫我宁姐
2018-11-19 08:35
采纳率: 66.7%
浏览 1.2k
已采纳

map 运行报错,路径错误,乱七八糟的,问问大神该怎样修改,以下是报错代码

nmap.nmap.PortScannerError: 'nmap program was not found in path. PATH is : /Users/liangjianing/anaconda3/share/jupyter/kernels/python3/anaconda3/bin:/Users/liangjianing/anaconda3/bin:/Library/Java/JavaVirtualMachines/jdk1.8.0_171.jdk/Contents/Home/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:.'
路径乱七八糟的,怎么跑到JAVA那里去了,请问大神怎样修改
补充错误
Traceback (most recent call last):
File "/Users/liangjianing/Desktop/Violent-Python-Examples-master/Chapter-2/2-nmapScan.py", line 31, in
main()
File "/Users/liangjianing/Desktop/Violent-Python-Examples-master/Chapter-2/2-nmapScan.py", line 27, in main
nmapScan(tgtHost, tgtPort)
File "/Users/liangjianing/Desktop/Violent-Python-Examples-master/Chapter-2/2-nmapScan.py", line 5, in nmapScan
nmScan = nmap.PortScanner()
File "/Users/liangjianing/anaconda3/share/jupyter/kernels/python3/anaconda3/lib/python3.7/site-packages/nmap/nmap.py", line 131, in init
os.getenv('PATH')
源代码
import nmap
import optparse

def nmapScan(tgtHost,tgtPort):
nmScan = nmap.PortScanner()
nmScan.scan(tgtHost,tgtPort)
state=nmScan[tgtHost]['tcp'][int(tgtPort)]['state']
print ("[*] " + tgtHost + " tcp/"+tgtPort +" "+state)

def main():
parser = optparse.OptionParser('usage %prog '+\
'-H -p ')
parser.add_option('-H', dest='tgtHost', type='string',\
help='specify target host')
parser.add_option('-p', dest='tgtPort', type='string',\
help='specify target port[s] separated by comma')

(options, args) = parser.parse_args()

tgtHost = options.tgtHost
tgtPorts = str(options.tgtPort).split(',')

if (tgtHost == None) | (tgtPorts[0] == None):
    print (parser.usage)
    exit(0)
for tgtPort in tgtPorts:
    nmapScan(tgtHost, tgtPort)

if name == '__main__':
main()

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • qq_24248933 2018-11-19 09:17
    已采纳

    在windows下,需要手动指定nmap的执行路径。在nmap.py初始化函数中加上自己机器上nmap可执行文件的路径即可。
    def init(self, nmap_search_path=('nmap','/usr/bin/nmap','/usr/local/bin/nmap','/sw/bin/nmap','/opt/local/bin/nmap',r"C:\Program Files\Nmap\nmap.exe") ):

    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • 明显是地址问题,但你给的东西太少了,没有遇到过这个问题不知道怎么解答,或许你能从这里python调用nmap进行扫描找到答案

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题