From 0246b2ebb863adc6f93e1c55d95fec2dfde38e25 Mon Sep 17 00:00:00 2001 From: Pierre LALET <pierre.lalet@cea.fr> Date: Sun, 31 Jan 2016 20:58:33 +0100 Subject: [PATCH] Update TracerouteResult.world_trace() to use Matplotlib --- scapy/layers/inet.py | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/scapy/layers/inet.py b/scapy/layers/inet.py index e6075163..badd1bba 100644 --- a/scapy/layers/inet.py +++ b/scapy/layers/inet.py @@ -10,7 +10,6 @@ IPv4 (Internet Protocol v4). import os,time,struct,re,socket,new from select import select from collections import defaultdict -import Gnuplot from scapy.utils import checksum from scapy.layers.l2 import * @@ -1112,7 +1111,7 @@ class TracerouteResult(SndRcvList): movcenter = visual.scene.mouse.pos - def world_trace(self): + def world_trace(self, **kargs): import GeoIP db = GeoIP.open(conf.geoip_city, 0) ips = {} @@ -1153,11 +1152,29 @@ class TracerouteResult(SndRcvList): if loctrace: trt[trace_id] = loctrace - tr = map(lambda x: Gnuplot.Data(x,with_="lines"), trt.values()) - g = Gnuplot.Gnuplot() - world = Gnuplot.File(conf.gnuplot_world,with_="lines") - g.plot(world,*tr) - return g + # Mimic the default gnuplot output + if kargs == {}: + kargs = MATPLOTLIB_DEFAULT_PLOT_KARGS + lines = [plt.plot(*zip(*tr), **kargs) for tr in trt.itervalues()] + with open(conf.gnuplot_world) as fdesc: + curline = [] + for line in fdesc: + line = line.strip() + if not line: + plt.plot(*zip(*curline), color="r") + curline = [] + continue + if line.startswith('#'): + continue + curline.append(line.split()) + plt.plot(*zip(*curline)) + del curline + + # Call show() if matplotlib is not inlined + if not MATPLOTLIB_INLINED: + plt.show() + + return lines def make_graph(self,ASres=None,padding=0): if ASres is None: -- GitLab