在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → c#抓包示例

c#抓包示例

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:0.13M
  • 下载次数:133
  • 浏览次数:2575
  • 发布时间:2015-12-16
  • 实例类别:C#语言基础
  • 发 布 人:wgp8
  • 文件格式:.rar
  • 所需积分:2
 相关标签: C# c 抓包

实例介绍

【实例简介】
【实例截图】

【核心代码】

using System;
using System.Collections;
using System.Windows.Forms;
using Tamir.IPLib;
using Tamir.IPLib.Packets;
using System.Threading;
using System.Text;

namespace MySniffer
{
    public partial class FrmSniff : Form
    {
        PcapDeviceList devices;
        PcapDevice device;
        Thread aThread;
        ArrayList PacketList = new ArrayList();
        int ARPCount = 0;
        int EthernetCount = 0;
        int ICMPCount = 0;
        int IGMPCount = 0;
        int IPCount = 0;
        int TCPCount = 0;
        int UDPCount = 0;

        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.Run(new FrmSniff());
        }



        public FrmSniff()
        {
            InitializeComponent();
            //
            // Windows 窗体设计器支持所必需的
            //

            this.button1.Click  = button1_Click;
            this.button2.Click  = button2_Click;
            this.listView1.ItemActivate  = listView1_ItemActivate;
            this.comboBox1.SelectedIndexChanged  = comboBox1_SelectedIndexChanged;

            devices = new PcapDeviceList();
            devices = SharpPcap.GetAllDevices();

            foreach (PcapDevice o in devices)
            {
                this.comboBox1.Items.Add(o.PcapDescription);
            }
            //
            // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            //
            Control.CheckForIllegalCrossThreadCalls = false;
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            if (this.button1.Text == "开始抓包")
            {
                this.button1.Text = "结束抓包";
                aThread = new Thread(new ThreadStart(this.mydo));
                aThread.Start();

            }
            else
            {
                aThread.Abort();
                this.button1.Text = "开始抓包";
            }

        }
        private void mydo()
        {
            //int ind = this.comboBox1.SelectedIndex;
            this.device = devices[this.comboBox1.SelectedIndex];
            //this.device = devices[1];
            device.PcapOnPacketArrival  =
                new SharpPcap.PacketArrivalEvent(device_PcapOnPacketArrival);

            device.PcapOpen(true, 1000);
            string filter = this.textBox1.Text;
            if (this.textBox1.Text != null)
            {
                device.PcapSetFilter(filter);
            }

            device.PcapCapture(SharpPcap.INFINITE);
            device.PcapClose();
        }
        #region 添加基本信息


        private void AddInfo(Packet packet)
        {

            switch (packet.GetType().ToString().Substring(20))
            {
                case "TCPPacket":
                    TCPPacket tcp = (TCPPacket)packet;
                    TCPCount  ;
                    this.AddTCPPacketInfo(tcp);
                    break;
                case "ARPPacket":
                    ARPPacket arp = (ARPPacket)packet;
                    ARPCount  ;
                    this.AddARPPacketInfo(arp);
                    break;
                case "EthernetPacket":
                    EthernetPacket eth = (EthernetPacket)packet;
                    EthernetCount  ;
                    this.AddEthernetPacketInfo(eth);
                    break;
                case "ICMPPacket":
                    ICMPPacket icmp = (ICMPPacket)packet;
                    ICMPCount  ;
                    this.AddICMPPacketInfo(icmp);
                    break;
                case "IGMPPacket":
                    IGMPPacket igmp = (IGMPPacket)packet;
                    IGMPCount  ;
                    this.AddIGMPPacketInfo(igmp);
                    break;
                case "IPPacket":
                    IPPacket ip = (IPPacket)packet;
                    IPCount  ;
                    this.AddIPPacketInfo(ip);
                    break;
                case "UDPPacket":
                    UDPPacket udp = (UDPPacket)packet;
                    UDPCount  ;
                    this.AddUDPPacketInfo(udp);
                    break;
                default:
                    break;
            }
        }
        private void AddTCPPacketInfo(TCPPacket tcp)
        {
            ListViewItem aItem = new ListViewItem(this.PacketList.Count.ToString());
            aItem.SubItems.Add("TCP");
            aItem.SubItems.Add(tcp.Bytes.Length.ToString());
            aItem.SubItems.Add(tcp.SourceAddress);
            aItem.SubItems.Add(tcp.SourceHwAddress);
            aItem.SubItems.Add(tcp.SourcePort.ToString());
            aItem.SubItems.Add(tcp.DestinationAddress);
            aItem.SubItems.Add(tcp.DestinationHwAddress);
            aItem.SubItems.Add(tcp.DestinationPort.ToString());
            aItem.SubItems.Add(tcp.PcapHeader.Date.ToString());
            this.listView1.Items.Add(aItem);
        }
        private void AddUDPPacketInfo(UDPPacket udp)
        {
            ListViewItem aItem = new ListViewItem(this.PacketList.Count.ToString());
            aItem.SubItems.Add("UDP");
            aItem.SubItems.Add(udp.Bytes.Length.ToString());
            aItem.SubItems.Add(udp.SourceAddress);
            aItem.SubItems.Add(udp.SourceHwAddress);
            aItem.SubItems.Add(udp.SourcePort.ToString());
            aItem.SubItems.Add(udp.DestinationAddress);
            aItem.SubItems.Add(udp.DestinationHwAddress);
            aItem.SubItems.Add(udp.DestinationPort.ToString());
            aItem.SubItems.Add(udp.PcapHeader.Date.ToString());
            this.listView1.Items.Add(aItem);
        }
        private void AddARPPacketInfo(ARPPacket arp)
        {
            ListViewItem aItem = new ListViewItem(this.PacketList.Count.ToString());
            aItem.SubItems.Add("ARP");
            aItem.SubItems.Add(arp.Bytes.Length.ToString());
            aItem.SubItems.Add(arp.SourceProtoAddress);
            aItem.SubItems.Add(arp.SourceHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(arp.DestinationProtoAddress);
            aItem.SubItems.Add(arp.DestinationHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(arp.PcapHeader.Date.ToString());
            this.listView1.Items.Add(aItem);
        }
        private void AddIPPacketInfo(IPPacket ip)
        {
            ListViewItem aItem = new ListViewItem(this.PacketList.Count.ToString());
            aItem.SubItems.Add("IP");
            aItem.SubItems.Add(ip.Bytes.Length.ToString());
            aItem.SubItems.Add(ip.SourceAddress);
            aItem.SubItems.Add(ip.SourceHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(ip.DestinationAddress);
            aItem.SubItems.Add(ip.DestinationHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(ip.PcapHeader.Date.ToString());
            this.listView1.Items.Add(aItem);
        }
        private void AddICMPPacketInfo(ICMPPacket icmp)
        {
            ListViewItem aItem = new ListViewItem(this.PacketList.Count.ToString());
            aItem.SubItems.Add("ICMP");
            aItem.SubItems.Add(icmp.Bytes.Length.ToString());
            aItem.SubItems.Add(icmp.SourceAddress);
            aItem.SubItems.Add(icmp.SourceHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(icmp.DestinationAddress);
            aItem.SubItems.Add(icmp.DestinationHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(icmp.PcapHeader.Date.ToString());
            this.listView1.Items.Add(aItem);
        }
        private void AddIGMPPacketInfo(IGMPPacket igmp)
        {
            ListViewItem aItem = new ListViewItem(this.PacketList.Count.ToString());
            aItem.SubItems.Add("IGMP");
            aItem.SubItems.Add(igmp.Bytes.Length.ToString());
            aItem.SubItems.Add(igmp.SourceAddress);
            aItem.SubItems.Add(igmp.SourceHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(igmp.DestinationAddress);
            aItem.SubItems.Add(igmp.DestinationHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(igmp.PcapHeader.Date.ToString());
            this.listView1.Items.Add(aItem);
        }
        private void AddEthernetPacketInfo(EthernetPacket eth)
        {
            ListViewItem aItem = new ListViewItem(this.PacketList.Count.ToString());
            aItem.SubItems.Add("Ethernet");
            aItem.SubItems.Add(eth.Bytes.Length.ToString());
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(eth.SourceHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(eth.DestinationHwAddress);
            aItem.SubItems.Add("null");
            aItem.SubItems.Add(eth.PcapHeader.Date.ToString());
            this.listView1.Items.Add(aItem);
        }


        #endregion

        #region 添加详细信息
        private void AddDetailInfo(Packet packet)
        {

            switch (packet.GetType().ToString().Substring(20))
            {
                case "TCPPacket":
                    TCPPacket tcp = (TCPPacket)packet;
                    this.AddTCPPacketDetailInfo(tcp);
                    break;
                case "ARPPacket":
                    ARPPacket arp = (ARPPacket)packet;
                    this.AddARPPacketDetailInfo(arp);
                    break;
                case "EthernetPacket":
                    EthernetPacket eth = (EthernetPacket)packet;
                    this.AddEthernetPacketDetailInfo(eth);
                    break;
                case "ICMPPacket":
                    ICMPPacket icmp = (ICMPPacket)packet;
                    this.AddICMPPacketDetailInfo(icmp);
                    break;
                case "IGMPPacket":
                    IGMPPacket igmp = (IGMPPacket)packet;
                    this.AddIGMPPacketDetailInfo(igmp);
                    break;
                case "IPPacket":
                    IPPacket ip = (IPPacket)packet;
                    this.AddIPPacketDetailInfo(ip);
                    break;
                case "UDPPacket":
                    UDPPacket udp = (UDPPacket)packet;
                    this.AddUDPPacketDetailInfo(udp);
                    break;
                default:
                    break;
            }
        }
        private void AddIGMPPacketDetailInfo(IGMPPacket igmp)
        {
            string headinfo = ChangeToASCII(igmp.IGMPHeader);
            string datainfo = ChangeToASCII(igmp.IGMPData);
            string totalinfo = ChangeToASCII(igmp.Bytes);
            this.richTextBox2.Text = string.Format("这是一个IGMP包\n转义为ASCII码的信息为:\n{0},\n其中包头信息转义为:{1}\n数据信息转义为:{2}\n具体信息如下:\n"  
                "Checksum:{3}\nColor:{4}\nDestinationAddress:{5}\nDestinationHwAddress:{6}\nEthernetHeaderLength:{7}\nEthernetProtocol:{8}\n"  
                "FragmentFlags:{9}\nFragmentOffset:{10}\nGroupAddress:{11}\nHeaderLength:{12}\nId:{13}\nIGMPChecksum:{14}\nIPChecksum:{15}\nIPHeaderLength:{16}\n"  
                "IPProtocol:{17}\nLength:{18}\nMaxResponseTime:{19}\nMessageType:{20}\nProtocol:{21}\nSourceAddress:{22}\n"  
                "SourceHwAddress:{23}\nTimeToLive:{24}\nTypeOfService:{25}\nValidChecksum:{26}\nValidIPChecksum:{27}\nVersion:{28}\n"
                , totalinfo, headinfo, datainfo, igmp.Checksum, igmp.Color, igmp.DestinationAddress, igmp.DestinationHwAddress, igmp.EthernetHeaderLength,
                igmp.EthernetProtocol, igmp.FragmentFlags, igmp.FragmentOffset, igmp.GroupAddress, igmp.HeaderLength, igmp.Id,
                igmp.IGMPChecksum, igmp.IPChecksum, igmp.IPHeaderLength, igmp.IPProtocol, igmp.Length, igmp.MaxResponseTime, igmp.MessageType,
                igmp.Protocol, igmp.SourceAddress, igmp.SourceHwAddress, igmp.TimeToLive, igmp.TypeOfService, igmp.ValidChecksum, igmp.ValidIPChecksum, igmp.Version);
        }
        private void AddTCPPacketDetailInfo(TCPPacket tcp)
        {
            string headinfo = ChangeToASCII(tcp.TCPHeader);
            string datainfo = ChangeToASCII(tcp.TCPData);
            string totalinfo = ChangeToASCII(tcp.Bytes);
            this.richTextBox2.Text = string.Format("这是一个TCP包\n转义为ASCII码的信息为:\n{0},\n其中包头信息转义为:{1}\n数据信息转义为:{2}\n具体信息如下:\n"  
                "Ack:{3}\nAcknowledgementNumber:{4}\nChecksum:{5}\nColor:{6}\nDestinationAddress:{7}\nDestinationHwAddress:{8}\n"  
                "DestinationPort:{9}\nEthernetHeaderLength:{10}\nEthernetProtocol:{11}\nFin:{12}\nFragmentFlags:{13}]\nFragmentOffset:{14}\nHeaderLength:{15}\n"  
                "Id:{16}\nIPChecksum:{17}\nIPHeaderLength:{18}\nLength:{19}\nPayloadDataLength:{20}\nProtocol:{21}\nPsh:{22}\nRst:{23}\nSequenceNumber:{24}\n"  
                "SourceAddress:{25}\nSourceHwAddress:{26}\nSourcePort{27}\nSyn:{28}\nTCPChecksum:{29}\nTCPHeaderLength:{30}\nTimeToLive:{31}\nTypeOfService:{32}\n"  
                "Urg:{33}\nUrgentPointer:{34}\nValidChecksum:{35}\nValidIPChecksum:{36}\nVersion:{37}\nWindowSize:{38}",
                totalinfo, headinfo, datainfo, tcp.Ack, tcp.AcknowledgementNumber, tcp.Checksum, tcp.Color, tcp.DestinationAddress, tcp.DestinationHwAddress,
                tcp.DestinationPort, tcp.EthernetHeaderLength, tcp.EthernetProtocol, tcp.Fin, tcp.FragmentFlags, tcp.FragmentOffset, tcp.HeaderLength,
                tcp.Id, tcp.IPChecksum, tcp.IPHeaderLength, tcp.Length, tcp.PayloadDataLength, tcp.Protocol, tcp.Psh, tcp.Rst, tcp.SequenceNumber,
                tcp.SourceAddress, tcp.SourceHwAddress, tcp.SourcePort, tcp.Syn, tcp.TCPChecksum, tcp.TCPHeaderLength, tcp.TimeToLive, tcp.TypeOfService,
                tcp.Urg, tcp.UrgentPointer, tcp.ValidChecksum, tcp.ValidIPChecksum, tcp.Version, tcp.WindowSize);

        }
        private void AddUDPPacketDetailInfo(UDPPacket udp)
        {
            string headinfo = ChangeToASCII(udp.UDPHeader);
            string datainfo = ChangeToASCII(udp.UDPData);
            string totalinfo = ChangeToASCII(udp.Bytes);
            this.richTextBox2.Text = string.Format("这是一个UDP包\n转义为ASCII码的信息为:\n{0},\n其中包头信息转义为:{1}\n数据信息转义为:{2}\n具体信息如下:\n"  
                "Checksum:{3}\nColor:{4}\nDestinationAddress:{5}\nDestinationHwAddress:{6}\nDestinationPort:{7}\nEthernetHeaderLength:{8}\nEthernetProtocol:{9}\n"  
                "FragmentFlags:{10}\nFragmentOffset:{11}\nHeaderLength:{12}\nId:{13}\nIPChecksum:{14}\nIPHeaderLength:{15}\nIPProtocol:{16}\n"  
                "Length:{17}\nProtocol:{18}\nSourceAddress:{19}\n"  
                "SourceHwAddress:{20}\nSourcePort:{21}\nTimeToLive:{22}\nTypeOfService:{23}\nUDPChecksum:{24}\nValidChecksum:{25}\nValidIPChecksum:{26}\nVersion:{27}\n",
                totalinfo, headinfo, datainfo, udp.Checksum, udp.Color, udp.DestinationAddress, udp.DestinationHwAddress, udp.DestinationPort,
                udp.EthernetHeaderLength, udp.EthernetProtocol, udp.FragmentFlags, udp.FragmentOffset, udp.HeaderLength, udp.Id,
                udp.IPChecksum, udp.IPHeaderLength, udp.IPProtocol, udp.Length, udp.Protocol, udp.SourceAddress, udp.SourceHwAddress,
                udp.SourcePort, udp.TimeToLive, udp.TypeOfService, udp.UDPChecksum, udp.ValidChecksum, udp.ValidIPChecksum, udp.Version);
        }

        private void AddARPPacketDetailInfo(ARPPacket arp)
        {
            string headinfo = ChangeToASCII(arp.ARPHeader);
            string datainfo = ChangeToASCII(arp.ARPData);
            string totalinfo = ChangeToASCII(arp.Bytes);

            this.richTextBox2.Text = string.Format("这是一个ARP包\n转义为ASCII码的信息为:\n{9},\n其中包头信息转义为:{10}\n数据信息转义为:{11}\n具体信息如下:\nProtocol:{0}\nOperation:{1}\nHeaderLength:{2}\n"  
            "SourceProtoAddress:{3}\nSourceHwAddress:{4}\nDestinationProtoAddress:{5}\nDestinationHwAddress:{6}\n"  
            "EthernetHeaderLength{7}\nEthernetProtocol:{8}",
                arp.Protocol, arp.Operation, arp.HeaderLength, arp.SourceProtoAddress, arp.SourceHwAddress,
                arp.DestinationProtoAddress, arp.DestinationHwAddress, arp.EthernetHeaderLength, arp.EthernetProtocol, totalinfo,
                headinfo, datainfo);
        }
        private void AddICMPPacketDetailInfo(ICMPPacket icmp)
        {
            string headinfo = ChangeToASCII(icmp.ICMPHeader);
            string datainfo = ChangeToASCII(icmp.ICMPData);
            string totalinfo = ChangeToASCII(icmp.Bytes);
            this.richTextBox2.Text = string.Format("这是一个ICMP包\n转义为ASCII码的信息为:\n{0},\n其中包头信息转义为:{1}\n数据信息转义为:{2}\n具体信息如下:\n"  
                "Checksum:{3}\nColor:{4}\nDestinationAddress:{5}\nDestinationHwAddress:{6}\nEthernetHeaderLength:{7}\nEthernetProtocol:{8}\n"  
                "FragmentFlags:{9}\nFragmentOffset:{10}\nHeaderLength:{11}\nICMPChecksum:{12}\nId:{13}\nIPChecksum:{14}\nIPHeaderLength:{15}\n"  
                "Length:{16}\nMessageCode:{17}\nMessageMajorCode:{18}\nMessageMinorCode:{19}\nMessageType:{20}\nProtocol:{21}\nSourceAddress:{22}\n"  
                "SourceHwAddress:{23}\nTimeToLive:{24}\nTypeOfService:{25}\nValidChecksum:{26}\nValidIPChecksum:{27}\nVersion:{28}\n"
                , totalinfo, headinfo, datainfo, icmp.Checksum, icmp.Color, icmp.DestinationAddress, icmp.DestinationHwAddress,
                icmp.EthernetHeaderLength, icmp.EthernetProtocol, icmp.FragmentFlags, icmp.FragmentOffset, icmp.HeaderLength,
                icmp.ICMPChecksum, icmp.Id, icmp.IPChecksum, icmp.IPHeaderLength, icmp.Length, icmp.MessageCode, icmp.MessageMajorCode,
                icmp.MessageMinorCode, icmp.MessageType, icmp.Protocol, icmp.SourceAddress, icmp.SourceHwAddress, icmp.TimeToLive,
                icmp.TypeOfService, icmp.ValidChecksum, icmp.ValidIPChecksum, icmp.Version);
        }
        private void AddIPPacketDetailInfo(IPPacket ip)
        {
            string headinfo = ChangeToASCII(ip.IPHeader);
            string datainfo = ChangeToASCII(ip.IPData);
            string totalinfo = ChangeToASCII(ip.Bytes);
            this.richTextBox2.Text = string.Format("这是一个IP包\n转义为ASCII码的信息为:\n{0},\n其中包头信息转义为:{1}\n数据信息转义为:{2}\n具体信息如下:\n"  
                "Checksum:{3}\nColor:{4}\nDestinationAddress:{5}\nDestinationHwAddress:{6}\nEthernetHeaderLength:{7}\nEthernetProtocol:{8}\n"  
                "FragmentFlags:{9}\nFragmentOffset:{10}\nHeaderLength:{11}\nId:{12}\nIPChecksum:{13}\nIPHeaderLength:{14}\n"  
                "IPProtocol:{15}\nLength:{16}\nProtocol:{17}\nSourceAddress:{18}\n"  
                "SourceHwAddress:{19}\nTimeToLive:{20}\nTypeOfService:{21}\nValidChecksum:{22}\nValidIPChecksum:{23}\nVersion:{24}\n",
                totalinfo, headinfo, datainfo, ip.Checksum, ip.Color, ip.DestinationAddress, ip.DestinationHwAddress, ip.EthernetHeaderLength,
                ip.EthernetProtocol, ip.FragmentFlags, ip.FragmentOffset, ip.HeaderLength, ip.Id, ip.IPChecksum, ip.IPHeaderLength, ip.IPProtocol,
                ip.Length, ip.Protocol, ip.SourceAddress, ip.SourceHwAddress, ip.TimeToLive, ip.TypeOfService, ip.ValidChecksum, ip.ValidIPChecksum, ip.Version);
        }
        private void AddEthernetPacketDetailInfo(EthernetPacket eth)
        {
            string headinfo = ChangeToASCII(eth.EthernetHeader);
            string datainfo = ChangeToASCII(eth.EthernetData);
            string totalinfo = ChangeToASCII(eth.Bytes);
            this.richTextBox2.Text = string.Format("这是一个Ethernet包\n转义为ASCII码的信息为:\n{0},\n其中包头信息转义为:{1}\n数据信息转义为:{2}\n具体信息如下:\n"  
                "Color:{3}\nDestinationHwAddress:{4}\nEthernetHeaderLength:{5}\nEthernetProtocol:{6}\nHeaderLength:{7}\nProtocol:{8}\nSourceHwAddress:{9}\n"
                , totalinfo, headinfo, datainfo, eth.Color, eth.DestinationHwAddress, eth.EthernetHeaderLength, eth.EthernetProtocol, eth.HeaderLength,
                eth.Protocol, eth.SourceHwAddress);
        }

        private string ChangeToASCII(byte[] by)
        {

            Encoding ascii = Encoding.ASCII;
            char[] tempchar = new char[ascii.GetCharCount(by, 0, by.Length)];
            ascii.GetChars(by, 0, by.Length, tempchar, 0);
            string tempout = new string(tempchar);
            string output = tempout.Replace("\0", ".");
            return output;
        }

        #endregion

        #region 统计信息
        private void Statistics()
        {
            int TotalCount = this.PacketList.Count;
            this.label12.Text = "总数:"   TotalCount.ToString();
            this.label13.Text = "TCP:"   TCPCount.ToString();
            this.label14.Text = "UDP:"   UDPCount.ToString();
            this.label15.Text = "ICMP:"   ICMPCount.ToString();
            this.label16.Text = "IGMP:"   IGMPCount.ToString();
            this.label17.Text = "IP:"   IPCount.ToString();
            this.label18.Text = "ARP:"   ARPCount.ToString();
            if (TotalCount == 0)
            {
                TotalCount = 1;
            }
            this.label19.Text = "Ethernet:"   EthernetCount.ToString();
            this.progressBar1.Value = TCPCount * 100 / TotalCount;
            this.label20.Text = this.progressBar1.Value.ToString()   "%";
            this.progressBar2.Value = UDPCount * 100 / TotalCount;
            this.label21.Text = this.progressBar2.Value.ToString()   "%";
            this.progressBar3.Value = ICMPCount * 100 / TotalCount;
            this.label22.Text = this.progressBar3.Value.ToString()   "%";
            this.progressBar4.Value = IGMPCount * 100 / TotalCount;
            this.label23.Text = this.progressBar4.Value.ToString()   "%";
            this.progressBar5.Value = IPCount * 100 / TotalCount;
            this.label24.Text = this.progressBar5.Value.ToString()   "%";
            this.progressBar6.Value = ARPCount * 100 / TotalCount;
            this.label25.Text = this.progressBar6.Value.ToString()   "%";
            this.progressBar7.Value = EthernetCount * 100 / TotalCount;
            this.label26.Text = this.progressBar7.Value.ToString()   "%";
        }

        #endregion



        private void device_PcapOnPacketArrival(object sender, Packet packet)
        {

            this.PacketList.Add(packet);
            this.AddInfo(packet);

            this.Statistics();
        }

        private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            this.label2.Text = "IP地址:";
            this.label3.Text = "子网掩码:";
            this.label4.Text = "MAC地址:";
            this.label5.Text = "默认网关:";
            this.label6.Text = "首选Wins服务器:";
            this.label7.Text = "备用Wins服务器:";
            this.label8.Text = "DHCP服务开启:";
            this.label9.Text = "DHCP服务器:";
            this.label10.Text = "DHCP租约获得时间:";
            this.label11.Text = "DHCP租约到期时间:";
            this.device = devices[this.comboBox1.SelectedIndex];
            if (this.device is NetworkDevice)
            {
                NetworkDevice netDev = (NetworkDevice)this.device;
                this.label2.Text  = netDev.IpAddress;
                this.label3.Text  = netDev.SubnetMask;
                this.label4.Text  = netDev.MacAddress;
                this.label5.Text  = netDev.DefaultGateway.ToString();
                this.label6.Text  = netDev.WinsServerPrimary.ToString();
                this.label7.Text  = netDev.WinsServerSecondary.ToString();
                this.label8.Text  = netDev.DhcpEnabled;
                this.label9.Text  = netDev.DhcpServer;
                this.label10.Text  = netDev.DhcpLeaseObtained.ToString();
            }
        }


        private void listView1_ItemActivate(object sender, System.EventArgs e)
        {
            //MessageBox.Show(this.listView1.SelectedItems[0].Text this.listView1.SelectedItems[0].SubItems[1].Text);
            Packet packet = (Packet)PacketList[Convert.ToInt16(this.listView1.SelectedItems[0].Text) - 1];
            this.richTextBox1.Text = null;
            foreach (byte o in packet.Bytes)
            {
                string hexo = Convert.ToString(o, 16).ToUpper();
                this.richTextBox1.Text  = string.Format("{0} ", hexo);
            }
            this.AddDetailInfo(packet);


        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            TCPCount = 0;
            UDPCount = 0;
            ICMPCount = 0;
            IGMPCount = 0;
            EthernetCount = 0;
            IPCount = 0;
            ARPCount = 0;
            this.richTextBox1.Text = null;
            this.richTextBox2.Text = null;

            this.listView1.Items.Clear();
            try
            {
                this.PacketList.Clear();
            }
            catch (Exception ee)
            {
                ;
            }

            this.Statistics();
        }

    }
}

标签: C# c 抓包

实例下载地址

c#抓包示例

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警