资源简介
利用Python快速分析数据包的完整性,提示数据包缺少步骤,按照源端口目的端口源ip和目的ip进行分流
代码片段和文件信息
#!/usr/bin/python
#coding=utf-8
import dpkt
import datetime
import socket
import os
from dpkt.compat import compat_ord
from dpkt.compat import BytesIO iteritems
import ConfigParser
import codecs
import sys
import zlib
from dpkt.gzip import Gzip
import getopt
import gzip binascii
from cStringIO import StringIO
global inIp
global inUrl
global inKeyword
default_encoding=“utf-8“
if(default_encoding!=sys.getdefaultencoding()):
reload(sys)
sys.setdefaultencoding(default_encoding)
class CResult:
def __init__(self seq=0 ack = 0 three = 0 gets=0 regets=0 oks=0rsts=0 bands=0 allblock=0keys=0str1=‘‘gzipflag=0 block=0 url=‘‘ get_seq=0 fszip=0):
self.seq = seq
self.ack = ack
self.three = three
self.url = url
self.gets = gets
self.regets = regets
self.block = block
self.allblock = allblock
self.str1 = str1
self.gzipflag = gzipflag
self.oks = oks
self.keys = keys
self.rsts = rsts
self.bands = bands
self.get_seq = get_seq
self.fszip = fszip
def readConfig():
cp = ConfigParser.SafeConfigParser()
with codecs.open(‘myapp.conf‘ ‘r‘ ‘utf-8‘) as f:
cp.readfp(f)
return cp
def inet_to_str(inet):
# First try ipv4 and then ipv6
return socket.inet_ntoa(inet)
def gzdecode(c_data):
buf = StringIO(c_data)
f = gzip.GzipFile(mode = ‘rb‘ fileobj = buf)
try:
r_data = f.read()
finally:
f.close()
return r_data
def printResult(dic urlSet):
gets=0
regets=0
three=0
oks=0
fins=0
rsts=0
bands=0
allblock = 0
flownum=0
keys = 0
zipfalsenum = 0
global inIp
global inUrl
global inKeyword
url = inUrl
if url.startswith(“http://“):
url = url[7:]
ipconf = inIp
keyword = inKeyword
if( len(keyword) > 0 ):
keyword_utf8=keyword.encode(‘utf-8‘)
keyutflen=len(keyword_utf8)
key_gbk=keyword.encode(‘gbk‘)
keygbklen=len(key_gbk)
print u“TCP流条数: “len(dic)
if(len(url) == 0):
if(len(urlSet) == 0):
print u“未发现url“
for tmpurl in urlSet:
for val in dic.values():
if val.url == tmpurl:
gets = gets + val.gets
regets = regets + val.regets
if val.three == 7:
three = three + 1
oks = oks + val.oks
rsts = rsts + val.rsts
bands = bands + val.bands
allblock = allblock + val.allblock
flownum = flownum + 1
print “+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++“
print u“URL: “ + tmpurl
if(flownum > three):
print “+++ “ u“三步握手丢失“.ljust(30) + str(flownum-three)
elif three == 0:
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-10-10 10:43 pcapanalysis\
文件 115253 2017-05-15 16:03 pcapanalysis\dpkt-1.9.1.tar.gz
目录 0 2017-10-10 10:43 pcapanalysis\parserpcap\
文件 14613 2017-07-03 15:09 pcapanalysis\parserpcap\parserpcap.py
文件 450 2017-07-03 15:23 pcapanalysis\pre_install_patch.sh
- 上一篇:泰坦尼克python数据分析
- 下一篇:Python爬取房价信息
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论