基本信息
源码名称:C# 简单的HTTP抓包例子源码下载
源码大小:0.03M
文件格式:.rar
开发语言:C#
更新时间:2015-03-26
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

调用底层抓包的例子

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WawaSoft.WawaCapturer;

namespace HttpZhuaZhua {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        RawSocket socket = null;


        private delegate void DgHTTPData(RawSocket.PacketArrivedEventArgs args);
        private DgHTTPData _showHttpMsg;

        private void Form1_Load(object sender, EventArgs e) {
            _showHttpMsg = new DgHTTPData(ShowHTTPData);

            socket = new RawSocket();
            socket.CreateAndBindSocket("172.26.4.170");
            if (socket.ErrorOccurred) {
                MessageBox.Show("监听出错了");
                return;
            }
            socket.PacketArrival  = socket_PacketArrival;

        }
        private void ShowHTTPData(RawSocket.PacketArrivedEventArgs args) {

            byte[] httpData = new byte[args.MessageLength - 20];
            Buffer.BlockCopy(args.MessageBuffer, 20, httpData, 0, httpData.Length);
            byte[] httpDataRe = new byte[args.ReceiveBuffer.Length - 20];
            Buffer.BlockCopy(args.ReceiveBuffer, 20, httpDataRe, 0, httpDataRe.Length);

            textBox1.AppendText("\r\n\r\n\r\n");
            textBox1.AppendText("Time:");
            textBox1.AppendText(DateTime.Now.ToString());
            textBox1.AppendText("|head:\r\n");
            textBox1.AppendText(args.ToString());
            textBox1.AppendText("\r\n httpData:\r\n");
            textBox1.AppendText(Encoding.UTF8.GetString(httpData));
            textBox1.AppendText("\r\n httpDataRe:\r\n");
            textBox1.AppendText(Encoding.UTF8.GetString(httpDataRe));
            textBox1.SelectionStart = textBox1.TextLength - 1;

        }


        void socket_PacketArrival(object sender, RawSocket.PacketArrivedEventArgs args) {
            if (args.Protocol == "TCP" && (args.OriginationPort == "80" || args.DestinationPort == "80")) {

                this.Invoke(_showHttpMsg, args);
                return;
            }
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e) {
            socket.Shutdown();
        }

        private void button1_Click(object sender, EventArgs e) {
            socket.KeepRunning = true;
            try {
                socket.Run();
            } catch (Exception ex) {
                MessageBox.Show(ex.ToString());
                throw;
            } finally {
            }
        }

        private void button2_Click(object sender, EventArgs e) {
            socket.KeepRunning = false;
        }

        private void btn_ClearLog_Click(object sender, EventArgs e) {
            textBox1.Clear();
        }
    }
}