Problems and solutions in the operation of Windows Python-nmap

Source: Internet
Author: User

1) Description of the problem

The following exception is thrown under Windows.

Traceback (most recent): File"ftplogin_file.py", line 111,inch<module>Main () File"ftplogin_file.py", line 109,inchmain FTPLogin (filepath) File"ftplogin_file.py", Line 77,inchFTPLoginifNmapscan (IP," +") ==True:file"ftplogin_file.py", line 8,inchNmapscan Nmscan=Nmap. Portscanner () File"C:\Python27\lib\site-packages\nmap\nmap.py", line 144,inch __init__      RaisePortscannererror ('Nmap program is not a found in path. PATH is: {0}'. F ormat (Os.getenv ('PATH')) Nmap.nmap.PortScannerError:'Nmap program is not a found in path. PATH is:c:\\wIndows\\system32; C:\\Windows; C:\\windows\\system32\\wbem; C:\\python27;d:\\wps of fice\\9.1.0.4468\\office6; C:\\Program Files\\Microsoft Visual Studio\\common\\to Ols\\winnt; C:\\Program Files\\Microsoft Visual Studio\\common\\msdev98\\bin; C:\\ Program Files\\Microsoft Visual Studio\\common\\tools; C:\\Program Files\\microso ft Visual Studio\\vc98\\bin'  

Where the exception is thrown

Nmscan = Nmap. Portscanner ()

2) Solutions

The exception is thrown because the execution path of NMAP is not specified, and the execution path of NMAP needs to be specified manually under Windows.

After modification

Nmscan = Nmap. Portscanner (nmap_search_path= (' Nmap ', r "H:\Nmap\nmap.exe"))

3) The complete code after the modification

ImportNmapImportOptparsedefNmapscan (tgthost,tgtport): Nmscan= Nmap. Portscanner (Nmap_search_path= ('Nmap'R"H:\Nmap\nmap.exe")) Nmscan.scan (tgthost,tgtport) state= nmscan[tgthost]['TCP'][int (Tgtport) [' State']    Print '[*]'+ Tgthost +'tcp/'+ Tgtport +' '+ StatedefMain (): Parser= Optparse. Optionparser ('Usage%prog'+'- H <target host>-p <target port>') 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):PrintParser.usage exit (0) forTgtportinchTgtports:nmapscan (Tgthost,tgtport)if __name__=='__main__': Main ()

4) run again and the results are as follows

D:\python-nmap>python2 test.py-h 192.168.1.44-p 21,22,1720[*]192.168.1.44 tcp/21 closed[*] 192.168.1.44 tcp/22 closed[*]192.168.1.44 tcp/1720 closed

Problems and solutions in the operation of Windows Python-nmap

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.