Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import xml.etree.ElementTree as etree
- from optparse import OptionParser, OptionGroup
- import sys
- # File to populate with missed hosts
- fname = 'missed-hosts.txt'
- parser = OptionParser(usage='usage: %prog -f <path/to/file.nessus>')
- parser.add_option('-f', '--file', action='store_true', dest='xml',
- help='designate Nessus XML file')
- (options, args) = parser.parse_args()
- # Get .nessus file location
- if options.xml:
- nessus = sys.argv[2]
- else:
- parser.print_help()
- sys.exit(0)
- #def check_from_file(all_hosts,nessus):
- # un_specifiedlist = list()
- # file_reader = open(location,'r')
- # for line in file_reader.readlines():
- # if line not in nessus:
- # un_specifiedlist.append(line)
- # writetofile(un_specifiedlist)
- def writetofile (arr):
- f = open(fname, 'a')
- f.write('Nessus missed the following hosts:\n')
- for i in arr:
- f.write(i + '\n')
- f.close()
- print '[+] Loading Nessus file...'
- # Attempt at parsing xml
- try:
- tree = etree.parse(nessus)
- except:
- print '[!] Invalid file'
- sys.exit(0)
- # Looks for all hosts inside the xml file
- print '[+] Finding all hosts....'
- hosts = tree.findall('.//ReportHost')
- if len(hosts) == 0:
- print '[!] No hosts extracted, invalid Nessus XML file'
- sys.exit(0)
- print '[+] Parsing through ReportItems...'
- missed_hosts = []
- for host in hosts:
- missed_hosts.append(host.attrib['name'])
- print '[+] Writing hosts to ' + fname
- writetofile(missed_hosts)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement