NMAP output format filtering Tool

Source: Internet
Author: User

You want to use NMAP to scan the IP segment and output a clean IP: Port file. So I wrote a simple script.

import xml.dom.minidomimport sysimport getoptstatstr=""statstrlist=["open"]infile=""outfile=""infileflag=0outfileflag=0statstrflag=0isstatflag=0helpflag=0#chu li can shuoptions,args = getopt.getopt(sys.argv[1:],"hni:o:s:",["help","in=","out=","stat"])for name,value in options:    if name in ("-h","--help"):        print """        xxoo.py            -h,--help print this help            -i,--in read the nmap xml outfile            -o,--out out the result (default: xmlname+_done.txt)            -s,--stat splited by dot (example:open.filtered.close default:open)            -n no status info        """        helpflag=1    if name in ("-i","--in"):        infile=value        infileflag=1    if name in ("-o","--out"):        outfile=value        outfileflag=1    if name in ("-s","--stat"):        statstrlist=value.split(".")        statflag=1    if name=="-n":        isstatflag=1#chu li mo ren can canshu if outfileflag==0:    outfile=infile+"_done.txt"if statstrflag==0:    statstrlist=["open"]if helpflag==1:    exit()#chu li domfile=open(outfile,"w+")dom=xml.dom.minidom.parse(infile)root=dom.documentElementhostlist=root.getElementsByTagName("host")for hostnode in hostlist:    for hostchild in hostnode.childNodes:        if hostchild.nodeName=="address":            ip=hostchild.getAttribute("addr")        if hostchild.nodeName=="ports":            for hostchildchild in hostchild.childNodes:                if hostchildchild.nodeName=="port":                    for stat in statstrlist:                        if hostchildchild.childNodes[0].getAttribute("state")==stat:                            if isstatflag==0:                                print ip+":"+hostchildchild.getAttribute("portid")+"(("+stat+"))"                                file.write(ip+":"+hostchildchild.getAttribute("portid")+"(("+stat+"))"+"\n")                            if isstatflag==1:                                print ip+":"+hostchildchild.getAttribute("portid")                                file.write(ip+":"+hostchildchild.getAttribute("portid")+"\n")                    #if hostchildchild.childNodes[0].getAttribute("state")=="open":                        #print ip+":"+hostchildchild.getAttribute("portid")+"((open))"                       # file.write(ip+":"+hostchildchild.getAttribute("portid")+"((open))"+"\n")                    #elif hostchildchild.childNodes[0].getAttribute("state")=="filtered":                       # print ip+":"+hostchildchild.getAttribute("portid")+"((filtered))"                      #  file.write(ip+":"+hostchildchild.getAttribute("portid")+"((filtered))"+"\n")                        file.close()



Use the Nmap-ox parameter to output the XML format file. Then tool-I name. XML-s open. Filtered

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.