def url_make_cmdStr(dbTableName): firsttime = httpdb.GetMin_timestamp(dbTableName) lasttime = httpdb.GetMax_timestamp(dbTableName) print 'pcap文件中http报文的时间段是从 %s 到 %s'%(commonlib.timeformat_sec_to_date(firsttime),commonlib.timeformat_sec_to_date(lasttime)) whileflag = True while flag : print '请输入开始时间,按照后面的格式: 2015-08-23 17:11:57' tempStr = '开始时间应该晚于 %s\r\n'%commonlib.timeformat_sec_to_date(firsttime) startime_date = str(raw_input(tempStr)) startime_input_sec = commonlib.timeformat_date_to_sec(startime_date) print '请输入结束时间,按照后面的格式: 2015-08-23 17:11:57 ' tempStr = '结束时间应该早于: %s\r\n'%commonlib.timeformat_sec_to_date(lasttime) endtime_date = str(raw_input(tempStr)) endtime_input_sec = commonlib.timeformat_date_to_sec(endtime_date) #时间有效性校验 if (endtime_input_sec > startime_input_sec) and (startime_input_sec > firsttime) and (endtime_input_sec < lasttime) : break else : print '输入时间错误,请重新输入\r\n' #SQL语句 cmsStr = "select * from %s where timestamp > %d and timestamp < %d"%(dbTableName,startime_input_sec,endtime_input_sec) return cmsStr
def url_make_cmdStr(dbTableName): firsttime = httpdb.GetMin_timestamp(dbTableName) lasttime = httpdb.GetMax_timestamp(dbTableName) print 'pcap文件中http报文的时间段是从 %s 到 %s' % (commonlib.timeformat_sec_to_date( firsttime), commonlib.timeformat_sec_to_date(lasttime)) whileflag = True while flag: print '请输入开始时间,按照后面的格式: 2015-08-23 17:11:57' tempStr = '开始时间应该晚于 %s\r\n' % commonlib.timeformat_sec_to_date( firsttime) startime_date = str(raw_input(tempStr)) startime_input_sec = commonlib.timeformat_date_to_sec(startime_date) print '请输入结束时间,按照后面的格式: 2015-08-23 17:11:57 ' tempStr = '结束时间应该早于: %s\r\n' % commonlib.timeformat_sec_to_date( lasttime) endtime_date = str(raw_input(tempStr)) endtime_input_sec = commonlib.timeformat_date_to_sec(endtime_date) #时间有效性校验 if (endtime_input_sec > startime_input_sec) and ( startime_input_sec > firsttime) and (endtime_input_sec < lasttime): break else: print '输入时间错误,请重新输入\r\n' #SQL语句 cmsStr = "select * from %s where timestamp > %d and timestamp < %d" % ( dbTableName, startime_input_sec, endtime_input_sec) return cmsStr
def keyword_statistcis(tablename,keyword,n): hel = httpdb.opendata(tablename) cur = hel[1].cursor() #统计计数 print '*******查找关键字: %s ********'%keyword #SQL语句,统计总数 countstr = "select count(*) from %s where url like '%%%s%%' or \ get like '%%%s%%' or referer like '%%%s%%'or origin like '%%%s%%' or\ host like '%%%s%%'"%(tablename,keyword,keyword,keyword,keyword,keyword) cur.execute(countstr) res = cur.fetchall() for line in res: print '关键字总数为 : %s'%line print #SQL语句,查找符合条件的记录 countstr = "select * from %s where url like '%%%s%%' or \ get like '%%%s%%' or referer like '%%%s%%'or origin like '%%%s%%' or\ host like '%%%s%%'"%(tablename,keyword,keyword,keyword,keyword,keyword) cur.execute(countstr) res = cur.fetchall() i = 0; #打印记录 for line in res: i = i+1 print commonlib.timeformat_sec_to_date(line[0]) j = 0 for h in line: print tabelStr[j],h j = j+1 print '\r\n' if i == n: break print '\r\n'