본문 바로가기

카테고리 없음

SMART FACTORY-패킷 단위 출력

반응형
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.Schema;
using SharpPcap;
using WindowsFormsApp4;

namespace _20200826_001
{
    // 1. 설치 - 캡쳐 - 목록 - 선택 - 오픈 - 캡쳐
    // 2. 캡쳐된 것을 요리하는 과정

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

        

        private int Del_Button_Device(object sender)
        {
            int DeviceNum = Convert.ToInt32((sender as Button).Name.Substring("Facto".Length));

            for (int iTemp = 0; iTemp < CaptureDeviceList.Instance.Count; iTemp++)
            {
                foreach (Control Temp in Controls) // controls라는 집합안에 버튼이 속해있음
                {
                    if (Temp.Name == ("Facto" + iTemp))
                    {
                        Controls.Remove(Temp);
                    }
                }
            }
            return DeviceNum;
        }
        private void Print_TCP(byte[] EtherData)

        {
            int XMargin = 10;
            int XSize = 120;
            int XInterval = 10;
            int YMargin = 15;
            int YSize = 20;
            int YInterval = 10;
            //DATA 입력
            List<FactoLabel> factoLabels = new List<FactoLabel>();
            factoLabels.Add(new FactoLabel(){ Name = "L4 Protocol",Value = "" });
           
            
            
           int Port1 =  BitConverter.ToUInt16(EtherData.Skip<byte>(34).Take(2).Reverse<byte>().ToArray(), 0);
           int Port2 =  BitConverter.ToUInt16(EtherData.Skip<byte>(36).Take(2).Reverse<byte>().ToArray(), 0);
            Port1 = (Port1 < 1024) ? Port1 : 65535;
            Port2 = (Port2 < 1024) ? Port2 : 65535;
            Port1 = (Port1 < Port2) ? Port1 : Port2;
            switch (Port1)
            {
                case 7:
                    factoLabels[0].Value = "ECHO";
                    break;
                case 13:
                    factoLabels[0].Value = "DAYTIME";
                    break;
                case 20:
                    factoLabels[0].Value = "FTP : Data";
                    break;
                case 21:
                    factoLabels[0].Value = "FTP : Control";
                    break;
                case 22:
                    factoLabels[0].Value = "Secure SHell";
                    break;
                case 23:
                    factoLabels[0].Value = "Telnet Protocol";
                    break;
                case 25:
                    factoLabels[0].Value = "SMTP";
                    break;
                case 37:
                    factoLabels[0].Value = "TIME Protocol";
                    break;
                case 53:
                    factoLabels[0].Value = "DNS";
                    break;
                case 80:
                    factoLabels[0].Value = "HTTP";
                    break;
                case 443:
                    factoLabels[0].Value = "HTTPS";
                    break;
                default:
                    factoLabels[0].Value = "Not Support";
                    break;

            }


            //factoLabels.Add(new FactoLabel() { Name = "L4 Protocol", Value = iNum.ToString() });

            UInt32 iNum = BitConverter.ToUInt16(EtherData.Skip<byte>(34).Take(2).Reverse<byte>().ToArray(), 0);
            factoLabels.Add(new FactoLabel() { Name = "Source Port", Value = iNum.ToString() });

            iNum = BitConverter.ToUInt16(EtherData.Skip<byte>(36).Take(2).Reverse<byte>().ToArray(), 0);
            factoLabels.Add(new FactoLabel() { Name = "Destination Port", Value = iNum.ToString() });
            
            iNum = BitConverter.ToUInt32(EtherData.Skip<byte>(38).Take(4).Reverse<byte>().ToArray(), 0);
            factoLabels.Add(new FactoLabel() { Name = "Sequence Number", Value = iNum.ToString() });
            
            iNum = BitConverter.ToUInt32(EtherData.Skip<byte>(38).Take(4).Reverse<byte>().ToArray(), 0);
            factoLabels.Add(new FactoLabel() { Name = "Ack Number", Value = iNum.ToString() });
            
            iNum = (uint)((EtherData[46] >> 4)*4);
            factoLabels.Add(new FactoLabel() { Name = "Offset", Value = iNum.ToString() });

            iNum = EtherData[47];
            
            factoLabels.Add(new FactoLabel() { Name = "Bit : Urgent", Value = (0 != (iNum & 1 << 5)).ToString() });
            factoLabels.Add(new FactoLabel() { Name = "Bit : Ack"   , Value = (0 != (iNum & 1 << 4)).ToString() });
            factoLabels.Add(new FactoLabel() { Name = "Bit : Push"  , Value = (0 != (iNum & 1 << 3)).ToString() });
            factoLabels.Add(new FactoLabel() { Name = "Bit : Res"   , Value = (0 != (iNum & 1 << 2)).ToString() });
            factoLabels.Add(new FactoLabel() { Name = "Bit : Syn"   , Value = (0 != (iNum & 1 << 1)).ToString() });
            factoLabels.Add(new FactoLabel() { Name = "Bit : Fin"   , Value = (0 != (iNum & 1 << 0)).ToString() });

            iNum = BitConverter.ToUInt16(EtherData.Skip<byte>(48).Take(2).Reverse<byte>().ToArray(), 0);
            factoLabels.Add(new FactoLabel() { Name = "Window Size", Value = iNum.ToString() });
            iNum = BitConverter.ToUInt16(EtherData.Skip<byte>(50).Take(2).Reverse<byte>().ToArray(), 0);
            factoLabels.Add(new FactoLabel() { Name = "Checksum", Value = string.Format("0x{0:X4}", iNum) });
            iNum =BitConverter.ToUInt16(EtherData.Skip<byte>(52).Take(2).Reverse().ToArray(), 0);
            factoLabels.Add(new FactoLabel() { Name = "Urgent Pointer", Value = string.Format("0x{0:X4}", iNum) });

            factoLabels.Add(new FactoLabel() { Name = "Bit : Fin", Value = (0 != (iNum & 1 << 0)).ToString() });
            factoLabels.Add(new FactoLabel() { Name = "Bit : Fin", Value = (0 != (iNum & 1 << 0)).ToString() });

            GroupBox groupBox = new GroupBox();
            groupBox.Location = new System.Drawing.Point(410,10) ;
            groupBox.Name = "GroupTCP";
            groupBox.Size = new Size(XMargin * 2 + XSize * 2 + XInterval, (YInterval + YSize) * factoLabels.Count + YMargin);
            groupBox.Text = "TCP Layer";
            ///////////////////////////////////////////////////////////////////////////////////////////////
            ///라벨설정
            for (int Count = 0; Count < factoLabels.Count; ++Count)
            {
                Label aLabel = new Label();
                aLabel.TextAlign = ContentAlignment.MiddleCenter;
                aLabel.Text = factoLabels[Count].Name;
                aLabel.Name = "****";
                aLabel.Size = new Size(XSize, YSize);
                aLabel.Location = new Point(XMargin, (YSize + YInterval) * Count + YMargin);
                aLabel.BorderStyle = BorderStyle.FixedSingle;
                groupBox.Controls.Add(aLabel);

                aLabel = new Label();
                aLabel.TextAlign = ContentAlignment.MiddleCenter;
                aLabel.Text = factoLabels[Count].Value;
                aLabel.Name = "****1";
                aLabel.Size = new Size(XSize, YSize);
                aLabel.Location = new Point(XMargin + XSize + XInterval, (YSize + YInterval) * Count + YMargin);
                aLabel.BorderStyle = BorderStyle.FixedSingle;
                groupBox.Controls.Add(aLabel);
            }

            //그룹박스 출력
            Controls.Add(groupBox);

        }

            private void Print_MAC(byte[] EtherData)
        {

            Label aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Destination MAC";
            aLabel.Name = "LabelDMAC";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 10);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Source MAC";
            aLabel.Name = "LabelSMAC";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 40);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "L2 Protocal";
            aLabel.Name = "LabelProto";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 70);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            
            
            string data = string.Format("{0:X2}", EtherData[0]);
            for (int iTemp = 1; iTemp < 6; ++iTemp)
            {
                data += string.Format("-{0:X2}", EtherData[iTemp]);
            }
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = data;
            aLabel.Name = "LabelDMACData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 10);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

            data = string.Format("{0:X2}", EtherData[6]);
            for (int iTemp = 7; iTemp < 12; ++iTemp)
            {
                data += string.Format("-{0:X2}", EtherData[iTemp]);
            }
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = data;
            aLabel.Name = "LabelSMACData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 40);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            int iNum = BitConverter.ToInt16(EtherData.Skip<byte>(12).Take(2).Reverse<byte>().ToArray(), 0);
            switch (iNum)
            {
                case 0x0800:
                    data = "IP";
                    break;
                case 0x0200:
                    data = "Xerox PUP";
                    break;
                case 0x0500:
                    data = "Sprite";
                    break;
                case 0x0806:
                    data = "Address resolution";
                    break;
                case 0x8035:
                    data = "Reverse ARP";
                    break;
                case 0x809B:
                    data = "AppleTalk protocol";
                    break;
                case 0x80F3:
                    data = "AppleTalk ARP";
                    break;
                case 0x8100:
                    data = "IEEE 802.1Q VLAN tagging";
                    break;
                case 0x8137:
                    data = "IPX";
                    break;
                case 0x86dd:
                    data = "IP protocol version 6";
                    break;
                case 0x9000:
                    data = "used to test interfaces";
                    break;
                default:
                    data = "Unknown";
                    break;
            }
            aLabel.Text = data;
            aLabel.Name = "LabelProtoData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 70);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);
        }

        private void Print_IP(byte[] IPData)
        {
            Label aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "IP Version";
            aLabel.Name = "LabelIPV";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 100);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "IP Head Length";
            aLabel.Name = "LabelIPHL";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 130);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "IP TOS";
            aLabel.Name = "LabelIPTOS";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 160);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);
            
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "IP Total Length";
            aLabel.Name = "LabelIPTL";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 190);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);
            
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "IP IDentification";
            aLabel.Name = "LabelIPID";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 220);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Fragment DF";
            aLabel.Name = "LabelFDF";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 250);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);
            
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Fragment MF";
            aLabel.Name = "LabelIFMF";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 270);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Fragment Offset";
            aLabel.Name = "LabelIFOFF";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 290);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);
           
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Time To Live";
            aLabel.Name = "LabelIPTTL";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 250);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Time To Live";
            aLabel.Name = "LabelPROTO";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 320);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "L3 Protocol";
            aLabel.Name = "LabelL3";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 350);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Header checkSum";
            aLabel.Name = "LabelIPCHECK";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 380);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Source ID";
            aLabel.Name = "LabelIPS";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 410);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleLeft;
            aLabel.Text = "Destination ID";
            aLabel.Name = "LabelIPD";
            aLabel.Size = new Size(120, 20);
            aLabel.Location = new Point(40, 440);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            aLabel.BackColor = Color.LightGray;
            Controls.Add(aLabel);
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            byte byteTemp = IPData[14];

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = "IPv"+(byteTemp >> 4).ToString();
            aLabel.Name = "LabelIPVData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 100);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = ((byteTemp & 0x0F) * 4).ToString()+" Bytes";
            aLabel.Name = "LabelIPHLData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 130);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);
           
            byteTemp = IPData[15];

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = String.Format("0X{0:X2}", byteTemp);
            aLabel.Name = "LabelIPTOSData"; 
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 160);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);
            
           
            int iNum = BitConverter.ToInt16(IPData.Skip<byte>(16).Take(2).Reverse<byte>().ToArray(), 0);
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = iNum.ToString() + " Bytes";
            aLabel.Name = "LabelIPTLData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 190);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);
            
            iNum = BitConverter.ToInt16(IPData.Skip<byte>(18).Take(2).Reverse().ToArray(), 0);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = iNum.ToString();
            aLabel.Name = "LabelIPIDData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 220);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);


            iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = (0 != (iNum & (1 << 14))).ToString(); //0이 들어가 있으면 거짓이다.
            aLabel.Name = "LabelFDFData"; //1BITE DONT FRAGMENT
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 250);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

            iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);
            
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = (0 != (iNum & (1 << 13))).ToString(); //0이 들어가 있으면 거짓이다.
            aLabel.Name = "LabelFMFData"; //1BITE MORE FRAGEMENT
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 270);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

            iNum = BitConverter.ToInt16(IPData.Skip<byte>(20).Take(2).Reverse().ToArray(), 0);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = (iNum & 0X1FFF).ToString();
            aLabel.Name = "LabelFOFFSETData";// 13BITES
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 290);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

           

            byteTemp = IPData[22];

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = byteTemp.ToString();
            aLabel.Name = "LabelTTLData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 320);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);
            
            byteTemp = IPData[23];  //-->14에 순서대로 번호르 더하면 됨
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            switch (byteTemp)
            {
                case 0:
                    aLabel.Text = "IP";
                    break;
                case 1:
                    aLabel.Text = "ICMP";
                    break;
                case 2:
                    aLabel.Text = "IGMP";
                    break;
                case 4:
                    aLabel.Text = "IPIP";
                    break;
                case 6:
                    aLabel.Text = "TCP";
                    break;
                case 8:
                    aLabel.Text = "EGP";
                    break;
                case 12:
                    aLabel.Text = "PUP";
                    break;
                case 17:
                    aLabel.Text = "UDP";
                    break;
                case 22:
                    aLabel.Text = "IDP";
                    break;
                case 29:
                    aLabel.Text = "TP";
                    break;
                case 33:
                    aLabel.Text = "DCCP";
                    break;
                case 41:
                    aLabel.Text = "IPV6";
                    break;

                default:
                    break;
            }
            aLabel.Name = "LabelPROTOData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 350);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

            iNum = BitConverter.ToInt16(IPData.Skip<byte>(24).Take(2).Reverse().ToArray(), 0);

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = string.Format("0x{0:X4}", iNum);
            aLabel.Name = "LabelIPCHKData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 380);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);

            IPAddress iPAddress = new IPAddress(IPData.Skip<byte>(26).Take(4).ToArray());

            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = iPAddress.ToString();
            aLabel.Name = "LabelIPSData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 410);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);
            
            iPAddress = new IPAddress(IPData.Skip<byte>(30).Take(4).ToArray());
            
            aLabel = new Label();
            aLabel.TextAlign = ContentAlignment.MiddleCenter;
            aLabel.Text = iPAddress.ToString();
            aLabel.Name = "LabelIPDData";
            aLabel.Size = new Size(140, 20);
            aLabel.Location = new Point(200, 440);
            aLabel.BorderStyle = BorderStyle.FixedSingle;
            Controls.Add(aLabel);
        }

        private void Facto_Click(object sender, EventArgs e)
        {
            int DeviceNum = Del_Button_Device(sender);
            CaptureDeviceList.Instance[DeviceNum].Open(DeviceMode.Normal, 0);
            RawCapture arawCapture = CaptureDeviceList.Instance[DeviceNum].GetNextPacket();// 패킷을 하나가져오는 과정
            Print_MAC(arawCapture.Data); // 1계층 출력
           
            int iNum = BitConverter.ToInt16(arawCapture.Data.Skip<byte>(12).Take(2).Reverse<byte>().ToArray(), 0);
            
            if (0X0800 == iNum)
            {
                Print_IP(arawCapture.Data);// 2계층 출력
               
                if (6 == arawCapture.Data[23]) //TCP 패킷일때
                {
                    Print_TCP(arawCapture.Data); // 3계층 출력
                }
                
                //byteTemp = IPData[23];  //-->14에 순서대로 번호르 더하면 됨
              
                //    case 6:
                //        aLabel.Text = "TCP";
                //        break;

                }
        }
       





            private void button1_Click(object sender, EventArgs e)
        {
            List<string> NicName = new List<string>();
            foreach (ICaptureDevice Temp in CaptureDeviceList.Instance)
            {
                string[] arrTemp = Temp.ToString().Split('\n');
                NicName.Add(arrTemp[1].Substring("FriendlyName: ".Length));
            }

            for (int iTemp = 0; iTemp < NicName.Count; iTemp++)
            {
                Button abutton = new Button();
                abutton.Text = NicName[iTemp];
                abutton.Name = "Facto" + iTemp;
                abutton.Location = new Point(10, 10 + iTemp * 30);
                abutton.Size = new Size(120, 22);
                abutton.BackColor = Color.White;
                abutton.Click += new EventHandler(Facto_Click);
                Controls.Add(abutton);
            }
            (sender as Button).Enabled = false;

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
        }
    }
}
반응형