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

📄 np_notesel.py

📁 该软件根据网络数据生成NetFlow记录。NetFlow可用于网络规划、负载均衡、安全监控等
💻 PY
📖 第 1 页 / 共 2 页
字号:
        self.entrymap.append((None, None))        self.listbox.insert(END, ' - End -')         self.entrymap.append((None, None))        self.listbox.insert(END, '')         self.entrymap.append((None, None))        ############################################################################    def mode_id(self):	#print 'mode_id'	self.mode = 'id'		self.listbox.delete(0, END)	self.entrymap = []	self.mentries()        self.meentries()	self.rentries()	self.mxentries()	for i in self.ilist:	    tagf = i[0]            tag = tagf[0]            label = tagf[1]            #type = tagf[2]            subents = i[1]                            	                # major list box entry: tag - one per obj            #print 'foo1', label            if self.anonymize:                anlab = self.subob.sub('xx.xx.xx.xx', label)            else:                anlab = label            self.listbox.insert(END, anlab + ' (%d)' % (len(subents)))            self.entrymap.append(([tagf], label))	    if self.expand_all or self.expdict.has_key(label):		for e in subents:		    # subsidiary entries - msg types associated with obj		    self.listbox.insert(END, '    ' + e)		    self.entrymap.append(([tagf], None))        self.tidy_end()                # make sure any expanded selection stays in sight        self.listbox.see(self.expand_see)        self.toolbar.entryconfig('By_Id', state=DISABLED)        self.toolbar.entryconfig('By_Type', state=NORMAL)	    ############################################################################    def mode_type(self):	#print 'mode_type expand_all=%d' % (self.expand_all)	self.mode = 'type'		self.listbox.delete(0, END)	self.entrymap = []	self.mentries()        self.meentries()	self.rentries()	self.mxentries()	for i in self.slist:            #print i	    # one major entry per msg type            label = i[0]            subents = i[1]	    self.listbox.insert(END, label + ' (%d)' % (len(subents)))            #entrytype = subents[0][2]	    self.entrymap.append((subents, label))	    if self.expand_all or self.expdict.has_key(label):		for tagf in subents:                    #tag = e[0]                    label = tagf[1]                    if self.anonymize:                        anlab = self.subob.sub('xx.xx.xx.xx', label)                    else:                        anlab = label                    #type = e[2]                    # subsidiary entries - objs associated with message type                    self.listbox.insert(END, '    ' + anlab)                    self.entrymap.append(([tagf], None))        self.tidy_end()        # make sure any expanded selection stays in sight        self.listbox.see(self.expand_see)        self.toolbar.entryconfig('By_Type', state=DISABLED)        self.toolbar.entryconfig('By_Id', state=NORMAL)############################################################################    def expand(self):	if self.expanded:	    self.toolbar.entryconfig(4, label='Expand')	    self.expdict = {}	    self.expand_all = 0	else:	    self.toolbar.entryconfig(4, label='Shrink')	    items = self.selections            if len(items):                self.expand_all = 0                self.expand_see = items[0]                for i in items:                    #self.expand_all = 0                    self.expdict[self.entrymap[i][1]] = 1		#print 'exp added %s' % (self.entrymap[i][2])	    else:		self.expand_all = 1                self.expand_see = 0	self.expanded = ~self.expanded	if self.mode == 'type':	    self.mode_type()	else:	    self.mode_id()	#restart	self.poll()############################################################################    def expand_lb(self, arg):         items = self.listbox.curselection()        try:            items = map(string.atoi, items)        except ValueError: pass        if len(items):            key = self.entrymap[items[0]][1]            if self.expdict.has_key(key):                del self.expdict[key]            else:                self.expdict[key] = 1            self.expand_see = items[0]            if self.expdict:                self.toolbar.entryconfig(4, label='Shrink')                self.expanded = 1                            if self.mode == 'type':                self.mode_type()            else:                self.mode_id()############################################################################    def clear(self):		self.root.after_cancel(self.pollid)	#self.clearb.config(state=DISABLED)	for i in self.selections:	    self.listbox.select_clear(i)	self.selections = []	# restart	self.poll()	    ############################################################################    def get_entries(self, log):        #        # Items list        # entries = (type, label, tag, message, message extension)        items = []        find = string.find        subob = self.subob        for s in log:            #print '\'%s\'' % (s)            s = s.lstrip().rstrip()            if not len(s):                continue            delim = find(s, ' ')            etype = s[:delim]            #print etype                        if etype == 'TCPConn':                start = find(s, '#', delim) + 1                delim = find(s, ' ', start)                label = s[start:delim]                mid = find(s, ':', delim)                if mid == -1:                    msg = s[delim]                    msge = ''                else:                    msg = s[delim:mid]                    msge = s[mid+2:]                try:                    # connection id?                    tag = int(s[start:delim])                except ValueError:                    print '%s not a conn tag' % (s[start:delim])                    sys.exit(1)                items.append((etype, label, tag, msg, msge))            elif etype == 'WebClient':                start = find(s, '#', delim) + 1                delim = find(s, ' ', start)                label = s[start:delim]                mid = find(s, ':', delim)                if mid == -1:                    msg = s[delim:]                    msge = ''                else:                    msg = s[delim:mid]                    msge = s[mid+2:]                # client tree reference?                tag = _inet_aton(s[start:delim])                if tag == 0:                    print '_inet_aton fail line = %s' % (s)                    sys.exit(1)                items.append((etype, label, tag, msg, msge))            elif etype == 'Rank':                start = delim+1                delim = find(s, ' ', start)                subtype = s[start:delim]                items.append((etype, subtype, s[start:], s, None))            elif etype == 'XMsg':                start = delim+1                fields = s[start:].split(':')                items.append((etype, fields[0].lstrip().rstrip(),                              fields[1].lstrip().rstrip(),                              fields[2].lstrip().rstrip(),                              fields[3].lstrip().rstrip()))            else:                # No recognisable type - just a message                #print s                #print s[:end]                items.append(('Msg', s[:], None, None, None))        #for i in items:            #print i        return items  ############################################################################    def make_items(self, log):        #        # wa is array of caller-specific items, logfile contains generic        # entries        def by_tag0(a, b):                        return by_tag(a[0], b[0])        def by_tag1(a, b):                        return by_tag(a[1], b[1])        def by_tag(a, b):            typea = a[2]            typeb = b[2]            if typea != typeb:                # different types                if typea > typeb:                    return 1                else:                    return -1            elif typea == 'TConn':                # connections - tag is integer conn id                return a[0] - b[0]            else:                # trees - label is dd address                ssa = string.split(a[1], '.')                ssb = string.split(b[1], '.')                for i in [0, 1, 2, 3]:                    sa = ssa[i]                    sb = ssb[i]                    lena = len(sa)                    lenb = len(sb)                    if lena == lenb:                        if sa > sb:                            return 1                        elif sa < sb:                            return -1                        else:                            continue                    else:                        return lena - lenb                        # Main fn starts here        	idict = {}	sdict = {}        # 'expandable' messages        xdict = {}	self.ilist = []	self.slist = []	self.rlist = []	self.mlist = []        self.xlist = []        mlist = []        self.emlist = []        # get the stuff from the log file        items  = self.get_entries(log)	for w in items:	    #print w	                type = w[0]	    if type == 'TCPConn' or type == 'WebClient':                # fields are: ([0] type, [1] label, [2] object tag,                #  [3] message, [4] message extension)                l = w[1] # label 		t = w[2] # object tag		s = w[3] # msg		d = w[4] # detail string		# collect by object tag		if not idict.has_key((t, l, type)):		    idict[(t, l, type)] = {}		ent = idict[(t, l, type)]		# collect message type and count for this object		msg = s+d		if not ent.has_key(msg):		    ent[msg] = 0		ent[msg] += 1		# collect by message key		if not sdict.has_key(s):		    sdict[s] = {}    		ent = sdict[s]		# collect objects for this message		if not ent.has_key((t, l, type)):		    ent[(t, l, type)] = 0		ent[t, l, type] += 1	    elif type == 'Rank':                # fields are: ([0] type, [1] subtype, [2] label,                #  [3] tag, [4] None)		self.rlist.append((w[1], w[2], w[3])) # already ordered            elif type == 'XMsg':                # fields are: ([0] type, [1] label, [2] obtype,                #  [3] tag, [4] sub-label)                if not xdict.has_key(w[1]):                    xdict[w[1]] = {}                d = xdict[w[1]]                key = (w[4], w[2])                if not d.has_key(key):                    d[key] = []                d[key].append(w[3])	    elif type == 'Msg':		#print 'appending mssg %s' % (w[1])		mlist.append(w[1])	# produce list of connections/trees 	tmplist = idict.items() # ([0]=(tag, label, type), [1]={msg strings})	tmplist.sort(by_tag0)	for e in tmplist:	    head = e[0]	    ents = []	    l = e[1].keys()	    l.sort()	    for f in l:		ents.append(f)	    # fields: ((object tag, label, type), [msg strings])	    self.ilist.append((head, ents))	# produce list of msg keys	tmplist = sdict.items() # ([0]=msg string, [1]={object tags})	tmplist.sort()	for e in tmplist:	    head = e[0]	    ents = []	    l = e[1].keys()	    #print l	    l.sort(by_tag)	    for f in l:		ents.append(f)	    # fields (key string, [(object tag, label, type)])	    self.slist.append((head, ents))        # produce list of calleable messages        tmplist = xdict.items()        for e in tmplist:            head = e[0]            ents = []            l = e[1].items()            l.sort()            for f in l:                ents.append((tuple(f[1]), f[0][0], f[0][1]))            # fields are (label, [((taglist), sub-label, obtype)]            self.xlist.append((head, ents))        # process plain/expandable messages        emdict = {}        ord = 0 # used to maintain entry ordering        for m in mlist:            if m.find('|') < 0:                self.mlist.append(m)            else:                #print m                splits = m.split('|')                d = emdict                for split in splits:                    split = split.lstrip().rstrip()                    if split:                        d = d.setdefault(split, (ord, {}))[1]                ord += 1        self.listify(emdict, self.emlist)	    ##############################################################################    def listify(self, dict, list):        def by_ord(a, b):            return a[1][0] - b[1][0]        l = dict.items()        l.sort(by_ord)        for e in l:            newl = []            if len(e[1][1]):                list.append(('%s (%d)' % (e[0], len(e[1][1])), newl))            else:                list.append(('%s' % (e[0]), newl))            self.listify(e[1][1], newl)            	    ############################################################################################################################################################def usage(scriptname):    print "usage: " + scriptname + "<log file>"    sys.exit(1)############################################################################## Fire up a NoteSel to summarise an nprobe analysis log#	def main():    scriptname = os.path.basename(argv[0])    try:        optlist, args = getopt.getopt(sys.argv[1:],                                      '')    except getopt.error, s:        print '%s: %s' % (scriptname, s)        usage(scriptname)        sys.exit(1)    optstr = ''    for opt in optlist:        pass    if len(args) != 1:        usage(scriptname)    try:        f = open(args[0], 'r')    except IOError, s:        print 'Can\'t open log file:', s        sys.exit(1)    ents = f.readlines()        Sellist([], ents, None, None)# Call main when run as scriptif __name__ == '__main__':        main()        	

⌨️ 快捷键说明

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