def traceroute(target, interface): cmd = ['traceroute', '-A'] if (interface): cmd.extend(['-i', interface]) cmd.append(target) if EXPCONFIG['verbosity'] > 1: print("doing traceroute to {} ...".format(target)) time_start = time.time() p = Popen(cmd, stdout=PIPE) data = p.communicate()[0] time_end = time.time() if EXPCONFIG['verbosity'] > 1: print("traceroute finished.") if EXPCONFIG['verbosity'] > 2: print("traceroute: {}".format(data)) try: traceroute = parse_traceroute(data) except Exception as e: traceroute = {'error': 'could not parse traceroute'} if not traceroute: traceroute = {'error': 'no traceroute output'} traceroute['time_start'] = time_start traceroute['time_end'] = time_end traceroute['raw'] = data.decode('ascii', 'replace') return traceroute
def traceroute(target, interface): cmd = ['traceroute', '-A'] if (interface): cmd.extend(['-i', interface]) cmd.append(target) if EXPCONFIG['verbosity'] > 1: print("doing traceroute...") time_start = time.time() p = Popen(cmd, stdout=PIPE) data = p.communicate()[0] time_end = time.time() if EXPCONFIG['verbosity'] > 1: print("traceroute finished.") if EXPCONFIG['verbosity'] > 2: print("traceroute: {}".format(data)) try: traceroute = parse_traceroute(data) except Exception as e: traceroute = {'error': 'could not parse traceroute'} if not traceroute: traceroute = {'error': 'no traceroute output'} traceroute['time_start'] = time_start traceroute['time_end'] = time_end traceroute['raw'] = data.decode('ascii', 'replace') with NamedTemporaryFile(mode='w+', prefix='tmptraceroute', suffix='.json', delete=False) as f: f.write(json.dumps(traceroute)) return f.name
def traceroute(target, interface): cmd = ["traceroute", "-A"] if (interface): cmd.extend(["-i", interface]) cmd.append(target) if EXPCONFIG["cnf_verbosity"] > 1: print("\n" + TAG + "Running traceroute against..." + target) time_start = time.time() p = Popen(cmd, stdout=PIPE) data = p.communicate()[0] time_end = time.time() if EXPCONFIG["cnf_verbosity"] > 1: print(TAG + "Traceroute finished.") if EXPCONFIG["cnf_verbosity"] > 2: print(TAG + "Traceroute result: \n{}".format(data)) try: traceroute = parse_traceroute(data) except Exception as e: traceroute = {"error": "could not parse traceroute"} if not traceroute: traceroute = {"error": "no traceroute output"} traceroute["time_start"] = time_start traceroute["time_end"] = time_end traceroute["raw"] = data.decode("ascii", "replace") return traceroute