Skip to content
Snippets Groups Projects
Commit 0246b2eb authored by Pierre LALET's avatar Pierre LALET
Browse files

Update TracerouteResult.world_trace() to use Matplotlib

parent 4581f834
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,6 @@ IPv4 (Internet Protocol v4). ...@@ -10,7 +10,6 @@ IPv4 (Internet Protocol v4).
import os,time,struct,re,socket,new import os,time,struct,re,socket,new
from select import select from select import select
from collections import defaultdict from collections import defaultdict
import Gnuplot
from scapy.utils import checksum from scapy.utils import checksum
from scapy.layers.l2 import * from scapy.layers.l2 import *
...@@ -1112,7 +1111,7 @@ class TracerouteResult(SndRcvList): ...@@ -1112,7 +1111,7 @@ class TracerouteResult(SndRcvList):
movcenter = visual.scene.mouse.pos movcenter = visual.scene.mouse.pos
def world_trace(self): def world_trace(self, **kargs):
import GeoIP import GeoIP
db = GeoIP.open(conf.geoip_city, 0) db = GeoIP.open(conf.geoip_city, 0)
ips = {} ips = {}
...@@ -1153,11 +1152,29 @@ class TracerouteResult(SndRcvList): ...@@ -1153,11 +1152,29 @@ class TracerouteResult(SndRcvList):
if loctrace: if loctrace:
trt[trace_id] = loctrace trt[trace_id] = loctrace
tr = map(lambda x: Gnuplot.Data(x,with_="lines"), trt.values()) # Mimic the default gnuplot output
g = Gnuplot.Gnuplot() if kargs == {}:
world = Gnuplot.File(conf.gnuplot_world,with_="lines") kargs = MATPLOTLIB_DEFAULT_PLOT_KARGS
g.plot(world,*tr) lines = [plt.plot(*zip(*tr), **kargs) for tr in trt.itervalues()]
return g 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): def make_graph(self,ASres=None,padding=0):
if ASres is None: if ASres is None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment