基于Winpcap的Windows网络抓包与还原心得

    新的一年工作的第一天想对过去两个月的学习做一个总结,这段时间对自我的认识和工作的心态发生了变化。对工作更加认真了,也意识到自己的责任。言归正传,下面的程序是基于winpcap的网络抓包与还原心得,望一同学习交流。

注:个人感觉很大一部分的时间是花在了思路上,因此主要是个人完成程序的思路。下面全凭记忆,主要是程序完成的过程。

涉及到的内容:

1)WinPcap库

2)MFC(花的时间较多,但感觉没有学到什么难过

3)HTTP与FTP本地下载与还原

4)fox代理邮箱的上传还原


Gui界面部分需要采用MFC控件,然后主线程用于GUI,后台线程用winpcap库捕获数据包并实时显示在界面上。然后重点就是还原。

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个基于WinPcap网络抓包Python程序的示例代码: ``` import socket import struct import sys import threading from ctypes import * from winpcapy import * # define constants PCAP_ERRBUF_SIZE = 256 # define structure for IP header class IP(Structure): _fields_ = [ ("ihl", c_ubyte, 4), ("version", c_ubyte, 4), ("tos", c_ubyte), ("len", c_ushort), ("id", c_ushort), ("offset", c_ushort), ("ttl", c_ubyte), ("protocol_num", c_ubyte), ("sum", c_ushort), ("src", c_ulong), ("dst", c_ulong) ] def __new__(self, data=None): return self.from_buffer_copy(data) def __init__(self, data=None): # map protocol constants to their names self.protocol_map = {1: "ICMP", 6: "TCP", 17: "UDP"} # human readable IP addresses self.src_address = socket.inet_ntoa(struct.pack("<L", self.src)) self.dst_address = socket.inet_ntoa(struct.pack("<L", self.dst)) # human readable protocol try: self.protocol = self.protocol_map[self.protocol_num] except: self.protocol = str(self.protocol_num) # define callback function for packet capture def packet_handler(header, data): # parse IP header ip_header = IP(data) # print out packet information print("Protocol: %s, Source: %s, Destination: %s" % (ip_header.protocol, ip_header.src_address, ip_header.dst_address)) def main(): # open network adapter for capturing errbuf = create_string_buffer(PCAP_ERRBUF_SIZE) adapter = pcap_open_live("eth0", 65536, 1, 1000, errbuf) if not adapter: print("Unable to open adapter: %s" % errbuf.value.decode("utf-8")) sys.exit(1) # start packet capture loop try: pcap_loop(adapter, -1, packet_handler, None) except KeyboardInterrupt: pass # close the adapter pcap_close(adapter) if __name__ == "__main__": main() ``` 这个程序使用WinPcap库来捕获网络数据包,并使用Python中的ctypes库来定义IP头的结构体。程序打开一个名为“eth0”的网络适配器,然后进入无限循环以捕获数据包。当用户按下Ctrl + C时,程序将退出循环并关闭适配器。程序还包括一个包处理程序回调函数,它将在每个捕获的数据包上运行,并打印有关该包的一些信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值