• 大小: 244KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-07-03
  • 语言: C#
  • 标签: 抓包  irisskin.dll  

资源简介

C#抓包程序实例,学习如何抓取数据包、抓取的数据包集合等,并使用了皮肤控件对窗口进行美化处理,初始化窗体皮肤实例,抓包时可以多个网卡同时抓取,循环抓取每个网卡的数据包,为每个网卡IP配置一个抓取实例,产生一个委托实例并添加到newPacket的事件列表中,并赋予委托执行方法为begainUpdateList,并添加事件newPacket的处理函数,并定义了事件newPacket的处理函数,在主线程上执行委托关联的函数,完成抓取数据的接收并显示,显示数据包详细信息等,

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;

namespace _2010123066cdj_Sniffor
{
    public partial class Monitor : Form
    {
        private packetMonitorcs[] packetMonitor;//数据包抓取实例
        private List packetList = new List();//抓取的数据包集合
        private int totalPacketLength = 0;//抓取的数据包总大小(单位字节)
        public Monitor()
        {
            InitializeComponent();
        }

        private void Monitor_Load(object sender EventArgs e)
        {
            //初始化Ip列表
            this.InitIpList();
            //初始化IP抓取实例
            this.InitMonitor();
            //初始化窗体皮肤
            this.skinEngineMain.SkinFile = “Midsummer.ssk“;
        }
        
        private void btnStart_Click(object sender EventArgs e)
        {
            //开始抓取数据包
            if (btnStart.Text == “开始抓取“)
            {
                //循环抓取每个网卡的数据包
                for (int i = 0; i < packetMonitor.Length; i++)
                {
                    if (cmbIpList.SelectedIndex == 0)
                    {
                        try
                        {
                            //第i个开始抓取
                            packetMonitor[i].begainMonitor();
                        }
                        catch
                        {
                            MessageBox.Show(“内部错误,请联系管理员“);
                        }
                    }
                    else
                    {
                        try
                        {
                            //抓取指定的Ip
                            packetMonitor[cmbIpList.SelectedIndex - 1].begainMonitor();
                        }
                        catch
                        {
                            MessageBox.Show(“内部错误,请联系管理员“);
                        }
                    }
                    btnStart.Text = “停止抓取“;
                    toolStripStatusLabel1.Text = “开始监测所有端口“;
                }     
            }
            //停止抓取
            else
            {
                for (int i = 0; i < packetMonitor.Length; i++)
                {
                    packetMonitor[i].Stop();
                }
                btnStart.Text = “开始抓取“;
                toolStripStatusLabel1.Text = “停止监测“;
            }
       
        }

        /// 
        /// 初始化ip列表
        /// 

        public void InitIpList()
        {
            //获取IP列表
            IPAddress[] hostIpAdress = otherHandle.getLocalIPAddress();
            //没有网卡
            if (hostIpAdress.Length == 0)
            {
                MessageBox.Show(“未监测到本机网卡,请确认本机网卡!“);
                Application.Exit();
            }
            foreach (IPAddress ip in hostIpAdress)
            {
                cmbIpList.Ite

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4327  2012-11-18 12:27  Sniffor\2010123066cdj_Sniffor\2010123066cdj_Sniffor.csproj

     文件        144  2012-11-18 12:25  Sniffor\2010123066cdj_Sniffor\app.config

     文件      91782  2012-11-18 13:17  Sniffor\2010123066cdj_Sniffor\bin\Debug\header.ico

     文件      91782  2012-11-18 13:18  Sniffor\2010123066cdj_Sniffor\bin\Debug\header2.ico

     文件     520192  2007-11-02 09:06  Sniffor\2010123066cdj_Sniffor\bin\Debug\irisskin.dll

     文件      12238  2008-06-04 11:46  Sniffor\2010123066cdj_Sniffor\bin\Debug\Midsummer.ssk

     文件       6323  2013-04-07 17:57  Sniffor\2010123066cdj_Sniffor\Monitor.cs

     文件      11033  2012-11-18 13:50  Sniffor\2010123066cdj_Sniffor\Monitor.Designer.cs

     文件     145101  2012-11-18 13:50  Sniffor\2010123066cdj_Sniffor\Monitor.resx

     文件       2219  2012-11-17 20:58  Sniffor\2010123066cdj_Sniffor\otherHandle.cs

     文件      11699  2012-11-18 13:55  Sniffor\2010123066cdj_Sniffor\packetcs.cs

     文件       2328  2012-11-18 13:27  Sniffor\2010123066cdj_Sniffor\packetDetail.cs

     文件       4911  2012-11-18 13:27  Sniffor\2010123066cdj_Sniffor\packetDetail.Designer.cs

     文件     144325  2012-11-18 13:27  Sniffor\2010123066cdj_Sniffor\packetDetail.resx

     文件       4979  2013-04-07 17:58  Sniffor\2010123066cdj_Sniffor\packetMonitorcs.cs

     文件        542  2013-04-07 17:58  Sniffor\2010123066cdj_Sniffor\Program.cs

     文件       1374  2012-11-16 21:33  Sniffor\2010123066cdj_Sniffor\Properties\AssemblyInfo.cs

     文件       2882  2012-11-18 12:25  Sniffor\2010123066cdj_Sniffor\Properties\Resources.Designer.cs

     文件       5612  2012-11-16 21:33  Sniffor\2010123066cdj_Sniffor\Properties\Resources.resx

     文件       1120  2012-11-18 12:25  Sniffor\2010123066cdj_Sniffor\Properties\Settings.Designer.cs

     文件        249  2012-11-16 21:33  Sniffor\2010123066cdj_Sniffor\Properties\Settings.settings

     文件        905  2012-11-16 21:33  Sniffor\2010123066cdj_Sniffor.sln

    ..A..H.     26112  2012-11-18 13:57  Sniffor\2010123066cdj_Sniffor.suo

    ..A..H.     45568  2013-04-01 17:17  Sniffor\2010123066cdj_Sniffor.v11.suo

     目录          0  2013-05-17 20:14  Sniffor\2010123066cdj_Sniffor\bin\Debug

     目录          0  2013-05-17 20:14  Sniffor\2010123066cdj_Sniffor\bin\Release

     目录          0  2013-05-17 20:14  Sniffor\2010123066cdj_Sniffor\bin

     目录          0  2013-05-17 20:14  Sniffor\2010123066cdj_Sniffor\obj

     目录          0  2013-05-17 20:14  Sniffor\2010123066cdj_Sniffor\Properties

     目录          0  2013-05-17 20:14  Sniffor\2010123066cdj_Sniffor

............此处省略4个文件信息

评论

共有 条评论