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

📄 np_notesel.py

📁 该软件根据网络数据生成NetFlow记录。NetFlow可用于网络规划、负载均衡、安全监控等
💻 PY
📖 第 1 页 / 共 2 页
字号:
#! /usr/bin/env python################################################################################                                                                             ##   Copyright 2005 University of Cambridge Computer Laboratory.               ##                                                                             ##   This file is part of Nprobe.                                              ##                                                                             ##   Nprobe is free software; you can redistribute it and/or modify            ##   it under the terms of the GNU General Public License as published by      ##   the Free Software Foundation; either version 2 of the License, or         ##   (at your option) any later version.                                       ##                                                                             ##   Nprobe is distributed in the hope that it will be useful,                 ##   but WITHOUT ANY WARRANTY; without even the implied warranty of            ##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             ##   GNU General Public License for more details.                              ##                                                                             ##   You should have received a copy of the GNU General Public License         ##   along with Nprobe; if not, write to the Free Software                     ##   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA ##                                                                             ############################################################################################################################################################################################################################################## #### ## #### ############################################################################ ############################################################################ import stringimport sysimport osfrom sys import argvimport getoptfrom Tkinter import *import print_col#import np_tcpfrom nprobe import http_server_objtype_string, http_server_returncode_string, _inet_aton, intoa_string, n2hlfrom np_lookups import np_hostnamefrom  np_longutil import *from minmax import *from np_plot import *from np_widgets import PListB, XYSCROLLfrom tkSimpleDialog import askstringimport re########################################################################################################################################################## Raised by error in callback fn#class CallBackError:    def __init__(self, val):        self.val = val    def __str__(self):	return self.val######################################################################################################################################################## class Sellist:    def __init__(self, draw_menu, log, obdict, callback, root=None,                 anonymize=0):	#self.path = path	#self.logfun = logfun        self.draw_menu = draw_menu        self.obdict = obdict        self.callback = callback        self.anonymize = anonymize        if anonymize:            self.subob = re.compile('\d+\.\d+\.\d+\.\d+')        else:            self.subob = None	self.make_items(log)        if not root:            self.root = Tk()            self.root.winfo_toplevel().title('Analysis log')        else:            self.root = root                    self.root.geometry('500x500')        self.root.minsize(200, 200)	self.frame = Frame(self.root)	self.frame.config(width=200, height=200, bg='red')	self.frame.pack(side=LEFT, fill=BOTH, expand=1)	self.toolbar = toolbar = Menu(self.frame)	toolbar.configure(bg='grey')	toolbar.add_command(label="Quit", command=self.quitfun,                             background='grey', foreground='red')	self.v = IntVar()	toolbar.add_radiobutton(label="By_Id", background='grey',				  variable=self.v, value=1, indicatoron=0, 				  command=self.mode_id)	toolbar.add_radiobutton(label="By_Type", background='grey',				    variable=self.v, value=2, indicatoron=0, 				    command=self.mode_type)	toolbar.add_command(label="Expand", background='grey', 			  command=self.expand)	toolbar.add_command(label="Clear", background='grey', 			  command=self.clear, state=DISABLED)        db = self.make_drawmenu()        toolbar.add_cascade(label='Draw', menu=db)        if not callback:            self.toolbar.entryconfig('Draw', state=DISABLED)        # Edit entries	toolbar.add_command(label="", background='grey', 			  command=self.edit)        self.root.config(menu=toolbar)	self.do_draw = None	self.expanded = 0	self.expand_all = 0        self.expand_see = 0	self.expdict = {}        self.listbox = PListB(self.frame, XYSCROLL)  	self.listbox.config(bg='white',  fg='black', selectborderwidth=0,  			       selectbackground='black',  			       selectforeground='white',  			       font = ('helvetica', 10), selectmode=EXTENDED) 	self.listbox.pack(side=LEFT, fill=BOTH, expand=1)        # Over-ride listbox method to give better results        self.listbox.inner_see = self.listbox.see        self.listbox.see = self.see                #        # Bind this to the root window so get listbox default behaviour        # (ie selection) PLUS a poll to identify the selection        #        self.root.bind("<Button-1>", self.poll_now)        self.listbox.bind("<Double-Button-1>", self.expand_lb)	self.mode_type()	self.poll() # start polling the list	self.root.mainloop() ############################################################################     def quitfun(self):	sys.exit(0) ############################################################################    def wheelscroll(self, ev):        #print 'scroll button %d' % (ev.num)        if ev.num == 4:            self.listbox.yview(SCROLL, -1, UNITS)        else:            self.listbox.yview(SCROLL, 1, UNITS)############################################################################    def edit(self):         items = self.listbox.curselection()         if not items:             return         indx = int(items[0])         s = self.listbox.get(indx)         print s         news = askstring('Log entry editor', 'Edit entry', initialvalue=s)         if news == None:             return         elif news and news == s:             return         else:              self.listbox.delete(indx)              if not news:                  return              newlines = news.split('\\')              for line in newlines:                  line = line.rstrip()                  self.listbox.insert(indx, line)                  indx += 1             ############################################################################    def make_drawmenu(self):        #        # keep track of draw menu entries        #        self.draw_what = StringVar() # radio button variable        # need these to keep track of button label for config indexing	self.men_centry = None	self.men_tentry = None        self.draw_menu.append(['Cancel', ['Cancel'], 0])        db = self.db = Menu(self.toolbar)        db.configure(background='grey')        self.button_groups = {}        i = 0        #print self.draw_menu        for l, gs, s in self.draw_menu:            db.add_radiobutton(label=l, command=self.drawfun, state=DISABLED,                             indicatoron=0, variable= self.draw_what, value=l,                               background='grey')            if s:                db.add_separator()            # register the button with its group            for g in gs:                 try:                    self.button_groups[g].append(l)                except KeyError:                    self.button_groups[g] = [l]            i += 1        return db                         ############################################################################    def poll_now(self, arg):        for e in self.draw_menu:            self.db.entryconfig(e[0], state=DISABLED)        self.poll()           ############################################################################     def poll(self):	draw_conns = 0	draw_trees = 0	draw_ranks = 0                try:            items = map(int, self.listbox.curselection())        except ValueError: pass        	#print '%d items selected' % (len(items))	if len(items):	    self.toolbar.entryconfig('Clear', state=NORMAL)	    #self.toolbar.drawb.entryconfig('Cancel', state=NORMAL)            active_buttons = {'Cancel': 1}	    for i in items:		entry = self.entrymap[i]                if not entry[0]:                    continue                for ent in entry[0]:                    type  = ent[2]                    try:                        buttons = self.button_groups[type] # activated for type                        # register the buttons to activate                        for button in buttons:                            active_buttons[button] = 1                    except KeyError:                        pass            # activate            for button in active_buttons.keys():                self.db.entryconfig(button, state=NORMAL)             	else:	    self.toolbar.entryconfig('Clear', state=DISABLED)            for e in self.draw_menu:                self.db.entryconfig(e[0], state=DISABLED)            self.pollid = self.root.after(100, self.poll)	self.selections = items        self.root.update_idletasks()		#print 'poll'############################################################################    def see(self, indx):        indx = min(indx+10, len(self.entrymap))        self.listbox.inner_see(indx)############################################################################    def draw_cancel(self):		for i in self.selections:	    self.listbox.select_clear(i)	self.selections = []        for e in self.draw_menu:            self.db.entryconfig(e[0], state=DISABLED)  	self.poll() # re-start	############################################################################    def drawfun(self):        what = self.draw_what.get()        #print '%x' % (what)        if what == 'Cancel':            self.draw_cancel()            return	items = self.selections	#print items	self.draw_cancel()	want = {} # objects to draw	for i in items:	    entry = self.entrymap[i]            if not entry[0]:                continue            for ent in entry[0]:                tag = ent[0]                if not want.has_key(ent):                    want[ent] = None # just want the entry        taglist = want.keys()        try:            self.callback(what, taglist, self.obdict)        except CallBackError, s:            print 'CallBackError \'%s\'' % (s)	# Finally re-start poll	self.poll()############################################################################    def rentries(self):        #pass        if len(self.rlist):            # fields are: ([0] subtype, [1] label,            #  [2] tag, [3] None)            self.listbox.insert(END, 'Ranks')             self.entrymap.append((None, None))            # delimiting blank line            self.listbox.insert(END, '')             self.entrymap.append((None, None))            this_subtype = ''             for e in self.rlist:                subtype = e[0]                 if subtype != this_subtype:                    this_subtype = subtype                    #print 'subtype', subtype                    self.listbox.insert(END, '  ' + subtype)                     self.entrymap.append((None, subtype))                if self.expdict.has_key(subtype):                    label = '    ' + e[1]                    tag = e[2]                    estr = label.replace(subtype, '')                    #print 'exp subtype', estr                    if self.anonymize and label.find('Client') >= 0:                        estr = self.subob.sub('xx.xx.xx.xx', estr)                    #self.listbox.insert(END, label)                    self.listbox.insert(END, estr)                     self.entrymap.append(([(tag, label, 'Rank '+subtype)], label))                    # To support this add list of conns to obdict entry                    ##                     if self.expdict.has_key(label):##                         # NB changed to tag[0]##                         for connid in self.obdict[tag][0]:##                             lab = '      #%d' % (connid)##                             self.listbox.insert(END, lab)##                             self.entrymap.append(([(connid, lab, 'TCPConn')], lab))                                     # delimiting blank line            self.listbox.insert(END, '')             self.entrymap.append((None, None))############################################################################    def mentries(self):        if len(self.mlist):                        for e in self.mlist:                if not len(e):                    # blank line                    self.listbox.insert(END, '')                     self.entrymap.append((None, None))                self.listbox.insert(END, e)                self.entrymap.append((None, e))                            # delimiting blank line            self.listbox.insert(END, '')             self.entrymap.append((None, None))############################################################################    def meentries(self):        def bl():            # insert a blank line            self.listbox.insert(END, '')             self.entrymap.append((None, None))        def entry(e, ind):                        if not len(e):                # blank line                self.listbox.insert(END, '')                 self.entrymap.append((None, None))                            self.listbox.insert(END, '   '*ind + e[0])             self.entrymap.append((None, e[0]))            if self.expand_all or self.expdict.has_key(e[0]):                ind += 1                if ind < 3 and e[1]:                    bl()                for en in e[1]:                    entry(en, ind)                if ind < 3 and e[1]:                    bl()                    for e in self.emlist:            entry(e, 0)        # delimiting blank line        bl()############################################################################    def mxentries(self):      ##   for i in self.xlist:##             print i                        if len(self.xlist):            for e in self.xlist:                k = e[0]                ents = e[1]                self.listbox.insert(END, k + ' (%d)' % (len(e[1])))                 self.entrymap.append((ents, k))                if self.expand_all or self.expdict.has_key(k):                    for ent in ents:                        if ent[1] != 'X':                            # subsidiary entries                            self.listbox.insert(END, '    ' + ent[1] + ' (%d)' % (len(ent[0])))                            self.entrymap.append(([ent], ent[1]))                # delimiting blank line                self.listbox.insert(END, '')                 self.entrymap.append((None, None))############################################################################    def tidy_end(self):                self.listbox.insert(END, '') 

⌨️ 快捷键说明

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