免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5893 | 回复: 3
打印 上一主题 下一主题

高分求Python分析Pcap格式的代码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-04-06 14:13 |只看该作者 |倒序浏览
30可用积分
高分求Python分析Pcap格式的代码,欢迎跟帖!

论坛徽章:
0
2 [报告]
发表于 2012-04-06 14:13 |只看该作者
  1.     class Writer(threading.Thread):
  2.         def __init__(self, product, stack):
  3.             threading.Thread.__init__(self)
  4.             self.product = product
  5.             self.stack = stack
  6.      
  7.             self.pcap_pkthdr = {}
  8.      
  9.         def run(self):
  10.             while True:
  11.                 filename = self.product.get()
  12.                 try:
  13.                     f = open(filename, "rb")
  14.                     readlines = f.read()
  15.                     f.close()
  16.                     offset = 24
  17.                     while len(readlines) > offset:
  18.                         self.pcap_pkthdr["len"] = readlines[offset+12:offset+16]
  19.                         try:
  20.                             length = struct.unpack("I", self.pcap_pkthdr["len"])[0]
  21.                             self.stack.put(readlines[offset+16:offset+16+length])
  22.                             offset += length + 16
  23.                         except Exception, errmsg:
  24.                             logger.error("unpack pcap_pkthdr failed: %s" % errmsg)
  25.                 except IOError, errmsg:
  26.                     logger.error("open file failed: %s" % errmsg)
复制代码

论坛徽章:
0
3 [报告]
发表于 2012-04-06 14:24 |只看该作者
这个主要是分析pcap格式的结构,分析结构体中内容哪些内容是你所需要的。

论坛徽章:
0
4 [报告]
发表于 2013-01-31 13:39 |只看该作者
程序可以参照这个解析pcap的python脚本:
https://github.com/xiaxiaocao/pyhttpcap
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP