def make_script(out, args): if out == sys.stdout: cprint(bcolors.HEADER, "{0:*^79}".format(out.name)) else: cprint(bcolors.HEADER, "{0:*^79}".format("<%s>" % out.name)) try: from LookupScanner import LookupScanner from ScriptGenerator import ScriptGenerator except ImportError as e: return imperr(e) for arg in args: print >> out, '#' * 79 print >> out, "# BEGIN LOG ::", arg lookup_scanner = LookupScanner(arg) obj_dict = lookup_scanner.scan() script_gen = ScriptGenerator() for key, msgs in obj_dict.items(): print >> out, "#", key, "count =", len(msgs) with open(str(msgs[-1]) + '.json', 'w') as fp: fp.write(msgs[-1].to_json()) script_gen.msg_obj_to_script(msgs[-1], out) print >> out, "# END LOG :: %s\n" % arg
def main(args): """Engine of the script.""" logzero.loglevel(logging.INFO) if args.verbose >= 1: logzero.loglevel(logging.DEBUG) logger.debug(args) parsedip = parseIp(ip=args.ip) records_flat = list(itertools.chain(*args.records)) parsedRecords = [] for record in records_flat: logger.debug("Parsing Record: %s" % record) r = tldextract.extract(record) parsedRecords.append( DnsRecord(domain=r.registered_domain, entry=r.fqdn)) if parsedip: logger.debug("Parsed IP: %s" % parsedip) scriptoutput = ScriptGenerator(records=parsedRecords, ip=parsedip.exploded, action=args.scriptouttype) else: cname = args.ip logger.debug("CNAME: %s" % args.ip) scriptoutput = ScriptGenerator(records=parsedRecords, cname=cname, action=args.scriptouttype) print(*scriptoutput.get_script(), sep="\n")
def __execute(self): strBuffer = StrBuffer.StrBuffer() strBuffer.writeln('* Running repeat %d of %d' % (self.__repeat + 1, self.__repeatNumber)) #Create temporal directory and prepare configuration files if os.path.isdir(self.__tempDir): shutil.rmtree(self.__tempDir) os.mkdir(self.__tempDir) self.__prepareSimulationFiles(self.__tempDir, self.__config, self.__configDir) #Create script using ScriptGenerator if self.__configGenerator.getDiscardTime() >= self.__configGenerator.getSimulationTime(): strBuffer.writeln('* ERROR: Discard time %.2f should be smaller than simulation time %.2f ' % (self.__configGenerator.getDiscardTime(), self.__configGenerator.getSimulationTime())) print strBuffer.getvalue() sys.exit() scriptGenerator = ScriptGenerator(self.__config, strBuffer) scriptGenerator.generate('Script.tcl', self.__tempDir, self.__repeat, strBuffer) #Run script simStartTime = time.time() out = open(os.path.join(self.__tempDir, 'out'), 'w') err = open(os.path.join(self.__tempDir, 'err'), 'w') strBuffer.writeln('* Simulation script on directory %s try %d' % (self.__tempDir, self.__try)) self.__p = subprocess.Popen(['ns', 'Script.tcl'], stdout=out, stderr=err, cwd=self.__tempDir) self.__timer = JVMCheckingTimer(JVM_DUMP_CHECK_TIME, self.__p, self.__tempDir) self.__timer.start() print strBuffer.getvalue() sys.stdout.flush() success = self.__p.wait() == 0 self.__timer.cancel() out.close() err.close() strBuffer = StrBuffer.StrBuffer() if not success: strBuffer.writeln('* ERROR: There was a problem during simulation execution on directory %s' % self.__tempDir) else: strBuffer.writeln('* Finished NS-2 simulation on directory %s. Running time: %s' % (self.__tempDir, TimeFormatter.formatTime(time.time() - simStartTime))) self.__compressOutputLog(strBuffer) print strBuffer.getvalue() sys.stdout.flush() return success
def main(args): """Enter the app.""" global victims logzero.loglevel(logging.INFO) if args.verbose >= 1: logzero.loglevel(logging.DEBUG) logger.debug(args) parsedip = parseIp(ip=args.ip) if not parsedip: cname = args.ip record_type = "A" if args.aaaa: record_type = "AAAA" logger.info("Record Type set to AAAA") if args.filenames: filenames = filenamesToList(args.filenames, args.file_ext) logger.debug("Filename(s) parsing: %s" % filenames) for filename in filenames: dnsp = DnsParser( parsedip, filename=filename, record_type=record_type, debug=args.debug, scriptOutType=args.scriptouttype, ) tmpresults = dnsp.run_parser() if tmpresults: victims.extend(tmpresults[:]) if not args.scriptouttype: logger.info("Results of run:") print(*victims, sep="\n") else: if parsedip: scriptoutput = ScriptGenerator( records=victims, ip=parsedip.exploded, action=args.scriptouttype ) elif cname: scriptoutput = ScriptGenerator( records=victims, cname=cname, action=args.scriptouttype ) # print("%s" % scriptoutput.get_script()) print(*scriptoutput.get_script(), sep="\n")