|
10鱼币
运行的代码如下,使用的文件名是nmap_scan.py:
- import nmap
- def nmap_scan(iplist,domain):
- filename='.\\res\\nmap_'+domain+'.txt'
- with open(filename,'w') as f:
- for host in iplist:
- nm=nmap.PortScanner()
- nm.scan(host,'1-1024','-Pn')
- f.write('######################################\n')
- f.write('Host: %s (%s)\n' % (host,nm[host].hostname()))
- f.write('State: %s\n' % nm[host].state())
- for proto in nm[host].all_protocols():
- f.write('###########\n')
- f.write('Protocol: %s\n' % proto)
- lport=list(nm[host][proto].keys())
- lport.sort()
- for port in lport:
- f.write('port : %s\tstate: %s\tservice: %s\n' % (port,nm[host][proto][port]['state'],nm[host][proto][port]['name']))
- f.write('######################################\n')
- if __name__=='__main__':
- nmap_target={'ip','ip','ip'}
- domain='domain'
- nmap_scan(nmap_target,domain)
复制代码 报错截图如下(第一次运行如上文件正常,再次运行就会报错):
我曾经遇到过这个报错,大意是我取的文件名与python内置模块的模块名重复了。
但首先,那一次是首次运行即失败,不会出现第一次运行正常,第二次报错的情况
其次,我尝试将自己的文件名复制到python根目录去搜索,并未发现相同文件名的模块
python-nmap版本为:python_nmap-0.6.1-py3.7
|
|