def testATaleOfTwoCitiesIPv6(self): trace = traceroute.TraceRoute(self.loop.ioloop) trace.IPVersion = 'IPv6' self._DoTrace(trace, 'of.times', 30) self.assertEqual(len(trace.RouteHopsList), 6) self.assertEqual(trace.RouteHopsNumberOfEntries, 6) self.assertEqual(trace.RouteHopsList[1].Host, 'it.was') self.assertEqual(trace.RouteHopsList[2].Host, 'the.best') self.assertEqual(trace.RouteHopsList[3].Host, 'of.times') self.assertEqual(trace.RouteHopsList[4].Host, 'it.was') self.assertEqual(trace.RouteHopsList[5].Host, 'the.worst') self.assertEqual(trace.RouteHopsList[6].Host, 'of.times') self.assertEqual( trace.RouteHopsList[1].HostAddress, '1000:1000:1000:1001::1') self.assertEqual( trace.RouteHopsList[2].HostAddress, '1000:1000:1000:1002::') self.assertEqual( trace.RouteHopsList[3].HostAddress, '1000:1000:1000:1003::') self.assertEqual( trace.RouteHopsList[4].HostAddress, '1000:1000:1000:1004:1e:1000:0:23') self.assertEqual( trace.RouteHopsList[5].HostAddress, '1000:1000:1000:1005::') self.assertEqual( trace.RouteHopsList[6].HostAddress, '1000:1000:1000:1006:1e:1000:0:21') self.assertEqual(trace.DiagnosticsState, 'Complete') # rounding up the last RTT in the trace self.assertEqual(trace.ResponseTime, 7)
def testTraceRouteCannotResolve(self): trace = traceroute.TraceRoute(self.loop.ioloop) self._DoTrace(trace, 'this-name-does-not-exist', 30) self.assertEqual(len(trace.RouteHopsList), 0) self.assertEqual(trace.DiagnosticsState, 'Error_CannotResolveHostName') self.assertEqual(trace.RouteHopsNumberOfEntries, 0) self.assertEqual(trace.ResponseTime, 0)
def testTraceIPv6Address(self): trace = traceroute.TraceRoute(self.loop.ioloop) self._DoTrace(trace, '1000:1000:1000:1000::1000', 30) self.assertEqual(trace.RouteHopsNumberOfEntries, 6) # spot-checkthat this is the IPv6 trace self.assertEqual( trace.RouteHopsList[1].HostAddress, '1000:1000:1000:1001::1') self.assertEqual(trace.DiagnosticsState, 'Complete')
def testTraceRouteLocalhost(self): trace = traceroute.TraceRoute(self.loop.ioloop) self._DoTrace(trace, '127.0.0.1', 1) self.assertEqual(len(trace.RouteHopsList), 1) self.assertEqual(trace.RouteHopsNumberOfEntries, 1) self.assertEqual(trace.RouteHopsList[1].Host, 'localhost') self.assertEqual(trace.RouteHopsList[1].HostAddress, '127.0.0.1') self.assertEqual(trace.DiagnosticsState, 'Error_MaxHopCountExceeded') self._DoTrace(trace, '::1', 2) self.assertEqual(len(trace.RouteHopsList), 1) self.assertEqual(trace.RouteHopsNumberOfEntries, 1) self.assertEqual(trace.RouteHopsList[1].Host, 'localhost') self.assertEqual(trace.RouteHopsList[1].HostAddress, '::1') self.assertEqual(trace.DiagnosticsState, 'Complete')
def testAlternateTraceRouteOutputFormat(self): trace = traceroute.TraceRoute(self.loop.ioloop) self._DoTrace(trace, 'shakespeare', 30) self.assertEqual(len(trace.RouteHopsList), 6) self.assertEqual(trace.RouteHopsNumberOfEntries, 6) self.assertEqual(trace.RouteHopsList[1].Host, 'the.fault') self.assertEqual(trace.RouteHopsList[2].Host, 'dear.brutus') self.assertEqual(trace.RouteHopsList[3].Host, 'is.not') self.assertEqual(trace.RouteHopsList[4].Host, 'in.our') self.assertEqual(trace.RouteHopsList[5].Host, 'stars.but') self.assertEqual(trace.RouteHopsList[6].Host, 'in.ourselves') self.assertEqual(trace.RouteHopsList[1].HostAddress, '192.168.1.1') self.assertEqual(trace.RouteHopsList[2].HostAddress, '15.99.15.99') self.assertEqual(trace.RouteHopsList[3].HostAddress, '20.20.20.20') self.assertEqual(trace.RouteHopsList[4].HostAddress, '40.40.40.40') self.assertEqual(trace.RouteHopsList[5].HostAddress, '60.60.60.60') self.assertEqual(trace.RouteHopsList[6].HostAddress, '80.80.80.80') self.assertEqual(trace.DiagnosticsState, 'Complete')
def testATaleOfTwoCities(self): trace = traceroute.TraceRoute(self.loop.ioloop) self._DoTrace(trace, 'of.times', 30) self.assertEqual(len(trace.RouteHopsList), 6) self.assertEqual(trace.RouteHopsNumberOfEntries, 6) self.assertEqual(trace.RouteHopsList[1].Host, 'it.was') self.assertEqual(trace.RouteHopsList[2].Host, 'the.best') self.assertEqual(trace.RouteHopsList[3].Host, 'of.times') self.assertEqual(trace.RouteHopsList[4].Host, 'it.was') self.assertEqual(trace.RouteHopsList[5].Host, 'the.worst') self.assertEqual(trace.RouteHopsList[6].Host, 'of.times') self.assertEqual(trace.RouteHopsList[1].HostAddress, '12.34.56.78') self.assertEqual(trace.RouteHopsList[2].HostAddress, '34.56.78.90') self.assertEqual(trace.RouteHopsList[3].HostAddress, '56.78.90.12') self.assertEqual(trace.RouteHopsList[4].HostAddress, '78.90.12.34') self.assertEqual(trace.RouteHopsList[5].HostAddress, '90.12.34.56') self.assertEqual(trace.RouteHopsList[6].HostAddress, '12.34.56.79') self.assertEqual(trace.DiagnosticsState, 'Complete') self.assertEqual(trace.ResponseTime, int(1.277))
def testTraceRoute(self): loop = tr.mainloop.MainLoop() trace = traceroute.TraceRoute(loop) self._DoTrace(loop, trace, '127.0.0.1', 1) self.assertEqual(len(trace.RouteHopsList), 1) self.assertEqual(trace.RouteHopsList[1].Host, 'localhost') self.assertEqual(trace.RouteHopsList[1].HostAddress, '127.0.0.1') self.assertEqual(trace.DiagnosticsState, 'Error_MaxHopCountExceeded') self._DoTrace(loop, trace, '::1', 2) self.assertEqual(len(trace.RouteHopsList), 1) self.assertTrue(trace.RouteHopsList[1].Host == 'localhost' or trace.RouteHopsList[1].Host == 'ip6-localhost') self.assertEqual(trace.RouteHopsList[1].HostAddress, '::1') self.assertEqual(trace.DiagnosticsState, 'Complete') self._DoTrace(loop, trace, 'this-name-does-not-exist', 30) self.assertEqual(len(trace.RouteHopsList), 0) self.assertEqual(trace.DiagnosticsState, 'Error_CannotResolveHostName') self._DoTrace(loop, trace, 'google.com', 30) self.assertTrue(len(trace.RouteHopsList) > 1) self.assertEqual(trace.DiagnosticsState, 'Complete')
def testValidateExports(self): trace = traceroute.TraceRoute(self.loop.ioloop) tr.handle.ValidateExports(trace)
m.drawparallels(range(0, 90, 20)) m.drawmeridians(range(0, 180, 20)) def gps_to_point(coord): x, y = m(coord[1], coord[0]) return (x, y) def plot_point(point): m.plot(point[0], point[1], 'ro') return # Transforms GPS coordinates to X,Y to be places on map points = map(gps_to_point, coords) # Adds points to map map(plot_point, points) # Separated X form Y in different arrays and plots lines x = [point[0] for point in points] y = [point[1] for point in points] m.plot(x, y, linewidth=2, color='r') plt.title("Ruta realizada") plt.show() if __name__ == '__main__': host_destino = sys.argv[1] ip_list = tr.TraceRoute(host_destino) lat_longs = geolocate(ip_list) plot(lat_longs)
def get_topology_links(): data = Retreive_from_couchdb.hosts_list('localhost', '5984', 'scan-test123') data = json.loads(data) insert_query = ''' UNWIND {links} AS link MERGE (h1:node_UP { name: link[0]['hostname'],address: link[0]['address'],mac: link[0]['mac'] }) MERGE (h2:node_UP { name: link[1]['hostname'], address: link[1]['address'],mac: link[1]['mac'] }) MERGE (h1)<-[:CONNECT_TO]->(h2); ''' ip = get_ipsource() gateway_0 = None curr_host = None gateway_info = [] gateway = [] local_net = [] node_nbr = 0 links = [] for node in data: dest_addr = node['address'] hops_info, hops_to = traceroute.TraceRoute(dest_addr) l = len(hops_to) # local network if l == 1: if hops_to[0] == ip: local_net.append(node) if node['address'] == ip: curr_host = node if hops_to[0] <> ip: gateway_0 = node gate_0 = { 'hostname': node['hostname'], 'address': node['address'], 'mac': node['mac'], 'hop_nbr': l } gateway.append(gate_0) #distant networks if l > 1: hop_nbr = 0 exist, gate = verify_gate(hops_to[0], gateway, data, hop_nbr) exist_curr = curr_host is not None if not exist_curr: exist_curr, curr_host = verify_curr_host(ip, data) if not exist_curr: host_info = { 'hostname': "localhost", 'address': ip, 'mac': " " } if exist_curr and exist: links.append([curr_host, gate]) if exist_curr and not exist: links.append([curr_host, hops_info[0]]) gateway.append(hops_info[0]) if not exist_curr and exist: links.append([host_info, gate]) if not exist_curr and not exist: links.append([host_info, hops_info[0]]) gateway.append(hops_info[0]) while hop_nbr < l - 1: exist, gate = verify_gate(hops_to[hop_nbr + 1], gateway, data, hop_nbr) if exist: links.append([links[len(links) - 1][1], gate]) if not exist: links.append( [links[len(links) - 1][1], hops_info[hop_nbr + 1]]) gateway.append(hops_info[hop_nbr + 1]) hop_nbr += 1 if hops_info[l - 1]['address'] <> node['address']: unknown_net = { 'hostname': "unknown network", 'address': "unreachable", 'mac': "", 'hop_nbr': l + 1 } links.append([links[len(links) - 1][1], unknown_net]) links.append([unknown_net, node]) node_nbr += 1 # local network for host in local_net: links.append([host, gateway_0]) driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "azerty159")) session = driver.session() session.run(insert_query, parameters={"links": links}) session.close() return 0