⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 np_obtree.py

📁 该软件根据网络数据生成NetFlow记录。NetFlow可用于网络规划、负载均衡、安全监控等
💻 PY
📖 第 1 页 / 共 5 页
字号:
	x = self.leftmargin	xinc = inc*scalef	tm = 0	n = self.view.xrange/inc	if not n:	    n = 1		#print "xinx = %d" % (inc)	# scale and key in tscale window, lines only in tree window	y3 = canv.ymin        y4 = canv.ymax		x = self.leftmargin	for l in range(n+2):	    y0 = self.toplabely	    y1 = y0+self.screen.tscalecanv_ysz	    TLINE(x, y0, x, y1, fill='black')	    l = LINE(x, y3, x, y4, fill='black')            canv.lower(l)	    sstr = '%d' % (tm/1000)	    TEXT(x, y0, text = sstr, fill='black', anchor = S, font=self.font10)	    x = x+xinc	    tm = tm+inc	bb = scanv.bbox(ALL)        try:            scanv.ysize = bb[3]-bb[1]        except:            print 'Can\'t get bounding box - setting ysize to 1000'            scanv.ysize = 1000	    #############################################################################    def draw_map(self, canv):	if canv.drawn:	    return	LINE = canv.create_line	RECT = canv.create_rectangle	xscalef =  self.view.mxfact	yscalef =  self.view.myfact	tm = self.map_margin        markers = []	if len(self.client.connlist) > 10:	    cw = 1	    ow = 2	else:	    cw = 2	    ow = 4	for conn in self.client.connlist:	    x0 = int(conn.xv0*xscalef)	    x1 = int(conn.xv1*xscalef)	    y = tm + int(conn.vy*yscalef)            if self.rooturl and not(conn in self.tree_conns):                col = 'grey39'            else:                col = 'blue'	    LINE(x0, y, x1, y, fill=col, width=cw)	for req in self.client.translist:            if self.rooturl and not (req in self.tree_trans):                continue	    y = tm + int(req.yv*yscalef)	    if req.cvalid:		cobtype = req.cobtype		ccolour = self.tdict[cobtype][1]		x0 = int(req.xvreqstart*xscalef)		x1 = int(req.xvreqend*xscalef)		if x1 == x0:		    x0 = x1 + 1		RECT(x0, y-ow, x1, y+ow, fill=ccolour, outline=ccolour)		req.mapreqx = (x0+x1)/2		req.mapreqy = y	    #if req.svalid:	    if 1: ###		sobtype = req.sobtype		scolour = self.tdict[sobtype][1]		x0 = int(req.xvrepstart*xscalef)		x1 = int(req.xvrepend*xscalef)		if x1 == x0:		    x0 = x1 + 1		RECT(x0, y-ow, x1, y+ow, fill=scolour, outline=scolour)		req.maprepx = (x0+x1)/2		req.maprepy = y            # mark as interesting            if (req.reflink and (req.reflink.type & LR_REDIRECT)) \               or ((not req.reflink) and not (len(req.downlinks))) \               or req.isfail \               or req.multi \               or req.fon:                markers.append((x0-2, y-ow))	for imp in self.client.dummytrans:                        if self.rooturl and not (imp in self.tree_trans):                continue            	    #print imp	    #y = tm + int(((imp.dummy.yv0+imp.dummy.yv1)/2)*yscalef)	    y = tm + int(((imp.yv0+imp.yv1)/2)*yscalef)	    #x0 = int(imp.dlinks[0].xvreqstart*xscalef)	    x0 = int(imp.firstrans.xvreqstart*xscalef)	    x1 = x0 + 10	    RECT(x0, y-ow, x1, y+ow, fill='', outline='black', width=cw)	    #imp.dummy.maprepx = imp.dummy.mapreqx = (x0+x1)/2	    #imp.dummy.maprepy = imp.dummy.mapreqy = y	    imp.maprepx = imp.mapreqx = (x0+x1)/2	    imp.maprepy = imp.mapreqy = y                    translist = self.client.translist + \                    [d for d in self.client.dummytrans if d.reflink]	for trans in translist:            if (not trans.reflink) or \                   (self.rooturl and not trans in self.tree_trans):                continue            else:                link = trans.reflink                ref = link.trans                if self.rooturl and not ref in self.tree_trans:                    continue		refx = ref.maprepx		obx = trans.mapreqx		refy = ref.maprepy		oby = trans.mapreqy		#print 'link (%d,%d) to (%d,%d)' % (refx, refy, obx, oby)		#self.draw_link(canv, refx, refy, obx, oby, colour, style, 			       #self.connht*yscalef, ow)		self.draw_link(canv, refx, refy, obx, oby, link.type, 			       self.connht*yscalef, ow)        # draw last so distinct        for m in markers:            #self.draw_sarrow(canv, m[0], m[1], 'red')            self.draw_mark(canv, 'Any - map', m[0], m[1], count=1) 	canv.drawn = 1	    #############################################################################    def init_map_port(self, canv):	xsz = canv.xsize	ysz = canv.ysize	map = self.map        canv.map = map	canv.draw_map_port = self.draw_map_port	canv.delete_map_port = self.delete_map_port	canv.find_gap_by_time = self.find_gap_by_time	map.port = None	#canv.tlc = [canv.xmin, 0]        canv.tlc = [canv.canvasx(0), canv.canvasy(0)]	canv.myfact = float(self.screen.map_canv_ht)/self.draw.ysize	canv.mysize = int(canv.myfact*canv.screenht)        canv.mxfact = self.view.scalef*self.view.mxfact	canv.mxoff = int(self.leftmargin*self.view.mxfact)	canv.mi = 0        return	    #############################################################################    def init_vmap_port(self, canv):	xsz = canv.xsize	ysz = canv.ysize	map = self.map	canv.draw_map_port = self.draw_vmap_port	canv.delete_map_port = self.delete_vmap_port	map.port = None	#canv.tlc = [canv.xmin, 0]        canv.tlc = [canv.canvasx(0), canv.canvasy(0)]	canv.mxfact = float(self.screen.uframe_width)/self.view.xsize	canv.myfact = float(self.screen.map_canv_ht)/self.view.ysize	canv.mxsize = int(canv.mxfact*self.screen.dframe_width)	canv.mysize = int(canv.myfact*canv.screenht)	canv.map = map	h = int(map.cget('height'))	#print 'h=%d' % (h)	w = int(map.cget('width'))	#print 'w=%d' % (w)	    #############################################################################    def draw_map_port(self, canv):	#	# Detail canvas has non-linear x-scale - use the gaps list to map 	# display screen x0, x1 coords to gap time, then scale and offset time 	# to map coords	#        map = canv.map	#if map.port:	    #self.delete_vmap_port(canv)        x1 = canv.tlc[0]        x2 = canv.tlc[0]+self.screen.dframe_width        gaps = self.gaps        #print 'x1=%d x2=%d' % (x1, x2)        try:            if x1 <= gaps[0][3]:                mx1 = 0            else:                i1 = self.find_gap(x1, gaps, 0, len(self.gaps)-1, G_BEFORE)                mx1 = int(gaps[i1][1]*canv.mxfact) + canv.mxoff            if x2 >= gaps[-1][3]:                mx2 = self.screen.uframe_width            else:                i2 = self.find_gap(x2, gaps, 0, len(self.gaps)-1, G_AFTER)                mx2 = int(gaps[i2][1]*canv.mxfact) + canv.mxoff            y0 = canv.tlc[1]*canv.myfact+1            y1 = y0 + canv.mysize-1        except (NotInRange, IndexError):            return	#print 'creating port %d %d %d %d' % (mx1, y0, mx2, y1)	if map.port:	    self.delete_vmap_port(canv)	map.port = map.create_rectangle(mx1, y0, mx2, y1, width=1, outline='red')	map.pl = mx1	    #############################################################################    def draw_vmap_port(self, canv):	map = canv.map	if map.port:	    self.delete_vmap_port(canv)	tlc = canv.tlc	x0 = tlc[0]*canv.mxfact+1	x1 = x0 + canv.mxsize-1	y0 = tlc[1]*canv.myfact+1	y1 = y0 + canv.mysize-1	#print 'creating port %d %d %d %d' % (x0, y0, x1, y1)	map.port = map.create_rectangle(x0, y0, x1, y1, width=1, outline='red')        map.pl = x0#############################################################################    def delete_map_port(self, canv):	map = canv.map	map.delete(map.port)#############################################################################    def delete_vmap_port(self, canv):        	map = canv.map	map.delete(map.port)#############################################################################    def build_tdict(self):	#	# object types	#	# (code: text, colour, client seen?, server seen?)	tdict = {            CT_NON_OBJECT: ['no object', '', 0, 0],	    CT_UNKNOWN: ['type unknown', 'grey50', 0, 0],	    1: ['text/html', 'orange1', 0, 0],	    4: ['text/xml', 'sienna1', 0, 0],	    2100: ['image/gif', 'SpringGreen', 0, 0],	    2200: ['image/jpeg', 'LawnGreen', 0, 0], 	    CT_POST_ERR: ['error', 'red', 0, 0],	    CT_UNSYNCH: ['unsynchronised', 'grey85', 0, 0],	    CT_OTHER: ['other', 'LightPink', 0, 0]	    }        for t in [(self.client.ctypedict.items(), 2),                  (self.client.stypedict.items(), 3)]:            i = t[1]            tlist = t[0]            for e in tlist:                type = e[0]                n = e[1]                if tdict.has_key(type):                    tdict[type][i] += n                else:                    tdict[type] = \                                [http_server_objtype_string(type),                                 self.object_cols[self.object_cols_indx], 0, 0]                    tdict[type][i] += n                    self.object_cols_indx = self.object_cols_indx + 1		    	self.tdict = tdict#############################################################################    def build_agentsdict(self):        keylist = ascii_letters        keylen = len(keylist)                self.agentdict = dict = {}        # each list = [(no. occurences, name)]        alist, slist = self.client.get_agentlists()        keyi = 0        self.alist = list = []        for a in alist:            list.append((a[0], a[1]))            dict[a[1]] = keylist[keyi]            keyi = (keyi+1)%keylen        #nagents = ord('A')        self.slist = list = []        for a in slist:            list.append((a[0], a[1]))            dict[a[1]] = keylist[keyi]            keyi = (keyi+1)%keylen#############################################################################    def get_agentdict(self, a):        #print 'val is', a        return self.agentdict[a]	    #############################################################################    def whoops(self, txt):	x = self.leftmargin + 2*self.keyfieldwidth	y = self.topkeyy + self.keyentryht*self.nwarnings	self.nwarnings = self.nwarnings + 1	self.view.create_text(x, y, text=txt, fill="red", font=self.font12bold)	self.draw.create_text(x, y, text=txt, fill="red", font=self.font12bold)	#############################################################################	    def draw(self, screen):        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'        print 'Drawing tree for %s %s' % (self.client.Class,                                          self.client.addr_str())##         print '(connections',##         for c in self.client.connlist:##             print ' %d' % (c.id),##         print ')'##         print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'        print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'        #self.client.build_event_list()        #self.client.find_curr_conns()                if self.client.rooturl:            self.rooturl = self.client.rooturl            try:                self.tree_trans, self.tree_conns = \                                 self.client.get_reftree(self.client.rooturl)            except TreeError:                print 'Not distinguishing tree'                self.rooturl = None        	self.screen = screen	indx = screen.indx 	self.set_draw_parms()	self.info = screen.canvlist[indx][0]	self.map = screen.canvlist[indx][1]        self.draw = screen.canvlist[indx][2][1]        self.view = screen.canvlist[indx][3][1]	self.draw_detailed(screen.canvlist[indx][2])	self.draw_view(screen.canvlist[indx][3])	self.init_vmap_port(self.view)	self.init_map_port(self.draw)	self.draw_map(self.map)	self.draw_info(self.info)#############################################################################	    def draw_detailed(self, canvasses):	c = self.draw #= canvasses[1]	if c.drawn:	    return	c.tree = self	c.mode = 'detailed'	self.drawscale = canvasses[0]	self.drawscale.mode = 'scale'	c.scroll_with = self.drawscale	self.drawscale.scroll_with = c	c.topy = 15	self.calc_yinc()	self.scale_canvas()	self.draw_reqs()	self.draw_conns()	self.draw_implied_objects()	self.draw_deps(c, self.connht, self.reqht/2)	bb = c.bbox(ALL)	c.xsize = bb[2]-bb[0] + self.rightmargin + self.leftmargin	c.ysize = bb[3]-bb[1] + self.bottommargin + self.topmargin	c.xsize = self.drawscale.xsize = ma

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -