示例#1
0
        private void SaveToAlarmLog(double Interval, PacketProperties Properties, string MessageBodyHex)
        {
            string path = "AlarmLog";

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string Head = Properties.CaptureTime + ",";

            Head += Properties.Interval + ",";
            Head += Properties.OriginationAddress + "," + Properties.OriginationPort + "," + Properties.DestinationAddress + "," + Properties.DestinationPort + ",";
            Head += MessageBodyHex.Replace("\r\n", string.Empty);
            path += "\\" + Properties.CaptureTime.Year + "-" + Properties.CaptureTime.Month + "-" + Properties.CaptureTime.Day + ".csv";
            if (File.Exists(path))
            {
                using (StreamWriter file = new StreamWriter(path, true, Encoding.UTF8))
                {
                    file.WriteLine(Head);
                    file.Close();
                }
            }
            else
            {
                using (StreamWriter file = new StreamWriter(path, true, Encoding.UTF8))
                {
                    file.WriteLine("捕获时间,间隔,源IP,源端口,目的IP,目的端口,消息内容");
                    file.WriteLine(Head);
                    file.Close();
                }
            }
        }
 protected virtual void UpdateForm(PacketProperties Properties, bool showSignal, bool showSignaling)
 {
     if (PacketArrival != null)
     {
         PacketArrival(this, Properties, showSignal, showSignaling);
     }
 }
示例#3
0
        private void Show(PacketProperties Properties)
        {
            switch (Properties.SendDir)
            {
            case SendDir.VOBCToZC:
                UpdateChart(FilterOptionForm.MaxVOBCToZC, Properties.OriginationAddress + "(" + Properties.OriginationPort + ")" + "-ZC", this.listViewVOBCToZC, this.chartVOBCtoZCLine, this.chartVOBCtoZCPie, VOBCToZC, Properties);
                break;

            case SendDir.VOBCToCI:
                UpdateChart(FilterOptionForm.MaxVOBCToCI, Properties.OriginationAddress + "(" + Properties.OriginationPort + ")" + "-CI", this.listViewVOBCToCI, this.chartVOBCToCILine, this.chartVOBCtoCIPie, VOBCToCI, Properties);
                break;

            case SendDir.VOBCToATS:
                UpdateChart(FilterOptionForm.MaxVOBCToATS, Properties.OriginationAddress + "(" + Properties.OriginationPort + ")" + "-ATS", this.listViewVOBCToATS, this.chartVOBCToATSLine, this.chartVOBCToATSPie, VOBCToATS, Properties);
                break;

            case SendDir.ZCToVOBC:
                UpdateChart(FilterOptionForm.MaxZCToVOBC, "ZC-" + Properties.DestinationAddress + "(" + Properties.DestinationPort + ")", this.listViewZCToVOBC, this.chartZCtoVOBCLine, this.chartZCtoVOBCPie, ZCToVOBC, Properties);
                break;

            case SendDir.CIToVOBC:
                UpdateChart(FilterOptionForm.MaxCIToVOBC, "CI-" + Properties.DestinationAddress + "(" + Properties.DestinationPort + ")", this.listViewCIToVOBC, this.chartCIToVOBCLine, this.chartCIToVOBCPie, CIToVOBC, Properties);
                break;

            case SendDir.ATSToVOBC:
                UpdateChart(FilterOptionForm.MaxATSToVOBC, "ATS-" + Properties.DestinationAddress + "(" + Properties.DestinationPort + ")", this.listViewATSToVOBC, this.chartATSToVOBCLine, this.chartATSToVOBCPie, ATSToVOBC, Properties);
                break;
            }
        }
示例#4
0
 public void ShowInForm(PacketProperties Properties)
 {
     if (this.IsHandleCreated)
     {
         this.BeginInvoke(new UpdateForm(Show), Properties);
     }
 }
示例#5
0
 private void CalculateInterval(PacketProperties Properties, ConfigurationProperties SourceDevice, ConfigurationProperties DestDevice)
 {
     if (DicInterval.Keys.Contains(SourceDevice.IP + "-" + SourceDevice.Port + "+" + DestDevice.IP + "-" + DestDevice.Port))
     {
         Properties.Interval = (Properties.CaptureTime - DicInterval[SourceDevice.IP + "-" + SourceDevice.Port + "+" + DestDevice.IP + "-" + DestDevice.Port]).TotalSeconds;
         DicInterval[SourceDevice.IP + "-" + SourceDevice.Port + "+" + DestDevice.IP + "-" + DestDevice.Port] = Properties.CaptureTime;
     }
     else
     {
         Properties.Interval = 0;
         DicInterval.Add(SourceDevice.IP + "-" + SourceDevice.Port + "+" + DestDevice.IP + "-" + DestDevice.Port, Properties.CaptureTime);
     }
     showSignal = true;
     if (!Pause)
     {
         UpdateForm(Properties, showSignal, showSignaling);
     }
     SaveToPcap(Properties);
 }
        private void DataFilterByIPAndPort(PacketProperties Properties)
        {
            bool IsSourceMeet = false;
            bool isDestMeet   = false;
            ConfigurationProperties SourceDevice = null;
            ConfigurationProperties DestDevice   = null;

            foreach (var Source in IPList.ConfigProperties)
            {
                if (Source.IsSourceChoose == true && Properties.OriginationAddress == Source.IP && Properties.OriginationPort == Source.Port)
                {
                    IsSourceMeet = true;
                    SourceDevice = Source;
                    break;
                }
            }
            if (IsSourceMeet)
            {
                foreach (var Dest in IPList.ConfigProperties)
                {
                    if (Dest.IsDestChoose == true && Properties.DestinationAddress == Dest.IP && Properties.DestinationPort == Dest.Port)
                    {
                        isDestMeet = true;
                        DestDevice = Dest;
                        break;
                    }
                }
                if (isDestMeet)
                {
                    if (SetSendDir(SourceDevice, DestDevice, Properties))
                    {
                        if (!Pause)
                        {
                            SaveToShowStorage(Properties);
                        }
                        SaveToPcap(Properties);
                    }
                }
            }
        }
示例#7
0
        private void DataFilterByIPAndPort(PacketProperties Properties)
        {
            bool IsSourceMeet = false;
            bool isDestMeet   = false;
            ConfigurationProperties SourceDevice = null;
            ConfigurationProperties DestDevice   = null;

            foreach (var Source in IPList.ConfigProperties)
            {
                if (Source.IsSourceChoose == true && Properties.OriginationAddress.Contains(Source.IP) && Properties.OriginationPort == Source.Port)
                {
                    IsSourceMeet = true;
                    SourceDevice = Source;
                    break;
                }
            }
            if (IsSourceMeet)
            {
                foreach (var Dest in IPList.ConfigProperties)
                {
                    if (Dest.IsDestChoose == true && Properties.DestinationAddress.Contains(Dest.IP) && Properties.DestinationPort == Dest.Port)
                    {
                        isDestMeet = true;
                        DestDevice = Dest;
                        break;
                    }
                }
                if (isDestMeet)
                {
                    if (SetSendDir(SourceDevice, DestDevice, Properties))
                    {
                        CalculateInterval(Properties, SourceDevice, DestDevice);
                    }
                }
            }
        }
示例#8
0
 private bool SetSendDir(ConfigurationProperties SourceDevice, ConfigurationProperties DestDevice, PacketProperties Properties)
 {
     if (SourceDevice.Type == "VOBC" && DestDevice.Type == "ZC")
     {
         Properties.SendDir = SendDir.VOBCToZC;
         return(true);
     }
     else if (SourceDevice.Type == "ZC" && DestDevice.Type == "VOBC")
     {
         Properties.SendDir = SendDir.ZCToVOBC;
         return(true);
     }
     else if (SourceDevice.Type == "CI" && DestDevice.Type == "VOBC")
     {
         Properties.SendDir = SendDir.CIToVOBC;
         return(true);
     }
     else if (SourceDevice.Type == "VOBC" && DestDevice.Type == "CI")
     {
         Properties.SendDir = SendDir.VOBCToCI;
         return(true);
     }
     else if (SourceDevice.Type == "ATS" && DestDevice.Type == "VOBC")
     {
         Properties.SendDir = SendDir.ATSToVOBC;
         return(true);
     }
     else if (SourceDevice.Type == "VOBC" && DestDevice.Type == "ATS")
     {
         Properties.SendDir = SendDir.VOBCToATS;
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#9
0
 protected virtual void UpdateForm(PacketProperties Properties)
 {
     ShowThread.ShowStorage.Add(Properties);
 }
示例#10
0
        public void Unpack(byte[] buf, int len, CatchSocket Pcap, bool bStatus_Signal, bool bStatus_Signaling)
        {
            showSignal    = false;
            showSignaling = false;
            if (bStatus_Signal)//解析信号数据包
            {
                this.Pcap                        = Pcap;
                CBTCPacketProperties             = new PacketProperties(len);
                CBTCPacketProperties.CaptureTime = DateTime.Now;
                Unpack(buf, len);
            }
            if (bStatus_Signaling)//解析信令数据包
            {
                this.Pcap = Pcap;
                byte protocol        = 0;
                uint version         = 0;
                int  sourcePort      = 0;
                int  destinationPort = 0;
                protocol        = buf[9];
                version         = (uint)((buf[0] & 0xf0) >> 4);
                sourcePort      = buf[20] * 256 + buf[21];
                destinationPort = buf[22] * 256 + buf[23];
                if ((protocol == 6) && (sourcePort == 3868 || destinationPort == 3868))//TCP-diameter  (黄罡)
                {
                    PacketProperties = new PacketProperties(len);
                    Array.Copy(buf, PacketProperties.Buf, len);
                    PacketProperties.BufLength          = len;
                    PacketProperties.IPHeaderLength     = (uint)((buf[0] & 0x0f) << 2);
                    PacketProperties.Version            = version.ToString();
                    PacketProperties.OriginationPort    = sourcePort.ToString();
                    PacketProperties.DestinationPort    = destinationPort.ToString();
                    PacketProperties.DestinationAddress = buf[16].ToString() + "." + buf[17].ToString() + "." + buf[18].ToString() + "." + buf[19].ToString();
                    PacketProperties.OriginationAddress = buf[12].ToString() + "." + buf[13].ToString() + "." + buf[14].ToString() + "." + buf[15].ToString();
                    PacketProperties.PacketLength       = (uint)len;
                    PacketProperties.MessageLength      = PacketProperties.PacketLength - PacketProperties.IPHeaderLength;
                    PacketProperties.MessagePacketHex   = readData.RRead(buf);//用于展示抓获报文的名称(readData.RRead(PacketBuffer))//yao
                    PacketProperties.PacketBuffer       = readData.SourceData;
                    PacketProperties.protocolid         = readData.protocolid;
                    showSignaling = true;
                    if (!Pause)
                    {
                        UpdateForm(PacketProperties, showSignal, showSignaling);
                    }
                    SaveToPcap_Signaling(PacketProperties);
                }
                else if ((protocol == 17) && (sourcePort == 2123 || destinationPort == 2123))//UDP-GTPv2 (黄罡)
                {
                    PacketProperties = new PacketProperties(len);
                    Array.Copy(buf, PacketProperties.Buf, len);
                    PacketProperties.BufLength          = len;
                    PacketProperties.IPHeaderLength     = (uint)((buf[0] & 0x0f) << 2);
                    PacketProperties.Version            = version.ToString();
                    PacketProperties.OriginationPort    = sourcePort.ToString();
                    PacketProperties.DestinationPort    = destinationPort.ToString();
                    PacketProperties.DestinationAddress = buf[16].ToString() + "." + buf[17].ToString() + "." + buf[18].ToString() + "." + buf[19].ToString();
                    PacketProperties.OriginationAddress = buf[12].ToString() + "." + buf[13].ToString() + "." + buf[14].ToString() + "." + buf[15].ToString();
                    PacketProperties.PacketLength       = (uint)len;
                    PacketProperties.MessageLength      = PacketProperties.PacketLength - PacketProperties.IPHeaderLength;
                    PacketProperties.MessagePacketHex   = readData.RRead(buf); //用于展示抓获报文的名称(readData.RRead(PacketBuffer))//yao
                    PacketProperties.protocolid         = readData.protocolid;
                    PacketProperties.PacketBuffer       = readData.SourceData; //SourceData是去掉头部之后的数据(gtpv2去掉ip和udp头部,其他两个只去掉ip头)
                    showSignaling = true;
                    if (!Pause)
                    {
                        UpdateForm(PacketProperties, showSignal, showSignaling);
                    }
                    SaveToPcap_Signaling(PacketProperties);
                }
                else if (protocol == 132)
                {
                    byte[] sctp = new byte[len - 20];
                    Array.Copy(buf, 20, sctp, 0, len - 20);//去除IP头部20字节
                    C.DeScChunk(sctp);
                    int PPID = C.paylaodProtocolIdentifier;
                    if (PPID == 18)//sctp-s1ap
                    {
                        PacketProperties = new PacketProperties(len);
                        Array.Copy(buf, PacketProperties.Buf, len);
                        if (buf[3] == PacketProperties.Buf[3])
                        {
                            byte a = 1;
                        }
                        PacketProperties.BufLength          = len;
                        PacketProperties.IPHeaderLength     = (uint)((buf[0] & 0x0f) << 2);
                        PacketProperties.Version            = version.ToString();
                        PacketProperties.OriginationPort    = sourcePort.ToString();
                        PacketProperties.DestinationPort    = destinationPort.ToString();
                        PacketProperties.DestinationAddress = buf[16].ToString() + "." + buf[17].ToString() + "." + buf[18].ToString() + "." + buf[19].ToString();
                        PacketProperties.OriginationAddress = buf[12].ToString() + "." + buf[13].ToString() + "." + buf[14].ToString() + "." + buf[15].ToString();
                        PacketProperties.PacketLength       = (uint)len;

                        PacketProperties.MessagePacketHex = readData.RRead(buf); //用于展示抓获报文的名称(readData.RRead(PacketBuffer))//yao
                        PacketProperties.protocolid       = readData.protocolid;
                        PacketProperties.MessageLength    = readData.s1apLength; //消息长度使用纯s1ap信令长度
                        PacketProperties.PacketBuffer     = readData.SourceData;
                        showSignaling = true;
                        if (!Pause)
                        {
                            UpdateForm(PacketProperties, showSignal, showSignaling);
                        }

                        SaveToPcap_Signaling(PacketProperties);
                    }
                    else if ((PPID == 0 || PPID == 46 || PPID == 47 || PPID == 132) && ((sourcePort == 3868) || (destinationPort == 3868) || (sourcePort == 60000) || (destinationPort == 60000)))//sctp-diameter(黄罡)
                    {
                        B.DecodeSctpChunk(sctp);
                        if (B.IsDiameter == 1)
                        {
                            PacketProperties = new PacketProperties(len);
                            Array.Copy(buf, PacketProperties.Buf, len);
                            PacketProperties.BufLength          = len;
                            PacketProperties.IPHeaderLength     = (uint)((buf[0] & 0x0f) << 2);
                            PacketProperties.Version            = version.ToString();
                            PacketProperties.OriginationPort    = sourcePort.ToString();
                            PacketProperties.DestinationPort    = destinationPort.ToString();
                            PacketProperties.DestinationAddress = buf[16].ToString() + "." + buf[17].ToString() + "." + buf[18].ToString() + "." + buf[19].ToString();
                            PacketProperties.OriginationAddress = buf[12].ToString() + "." + buf[13].ToString() + "." + buf[14].ToString() + "." + buf[15].ToString();
                            PacketProperties.PacketLength       = (uint)len;
                            PacketProperties.MessageLength      = PacketProperties.PacketLength - PacketProperties.IPHeaderLength;
                            PacketProperties.MessagePacketHex   = readData.RRead(buf);//用于展示抓获报文的名称(readData.RRead(PacketBuffer))//ya
                            PacketProperties.protocolid         = readData.protocolid;
                            PacketProperties.PacketBuffer       = readData.SourceData;
                            showSignaling = true;
                            if (Pause)
                            {
                                UpdateForm(PacketProperties, showSignal, showSignaling);
                            }
                            SaveToPcap_Signaling(PacketProperties);
                        }
                    }
                }
            }//黄罡2017.4.29
        }
示例#11
0
 private void SaveToPcap(PacketProperties Properties)      //修改林庆庆
 {
     CatchSocket.CBTCTemporaryStorage.Add(Properties);
 }
示例#12
0
 private void SaveToPcap_Signaling(PacketProperties Properties)      //修改林庆庆
 {
     CatchSocket.LTETemporaryStorage.Add(Properties);
 }
示例#13
0
        private void UpdateChart(double AlarmInterval, string Name, ListView listView_Data, Chart chartLine, Chart chartPie, List <string> NameSeries, PacketProperties Properties)
        {
            if (DicInterval.Keys.Contains(Name))
            {
                Properties.Interval = (Properties.CaptureTime - DicInterval[Name]).TotalSeconds;
                DicInterval[Name]   = Properties.CaptureTime;
            }
            else
            {
                Properties.Interval = 0;
                DicInterval.Add(Name, Properties.CaptureTime);
            }
            if (Convert.ToDouble(Properties.Interval) > AlarmInterval)
            {
                string MessageBodyHex = GetDataHex(Properties.MessageBuffer, 8, (int)Properties.MessageLength - 8);
                listView_Data.Items.Add(new ListViewItem(new string[] { Properties.CaptureTime.ToString("yyyy-MM-dd"), Properties.CaptureTime.ToString("HH:mm:ss:fff"), Properties.Interval.ToString(), Properties.OriginationAddress, Properties.DestinationAddress, MessageBodyHex }));
                SaveToAlarmLog(AlarmInterval, Properties, MessageBodyHex);
            }
            int indexOfSeries;

            if (NameSeries.Contains(Name))
            {
                indexOfSeries = NameSeries.IndexOf(Name);
            }
            else
            {
                NameSeries.Add(Name);
                DicColor.Add(Name, GetRandomColor());
                Series s1 = new Series();
                s1.Name = Name;
                chartLine.Series.Add(s1);
                indexOfSeries = NameSeries.IndexOf(Name);
            }
            if (chartLine.Series[indexOfSeries].Points.Count() >= 1500)
            {
                chartLine.Series[indexOfSeries].Points.Remove(chartLine.Series[indexOfSeries].Points[0]);
            }
            double Interval;

            Interval = Properties.Interval;
            if (Properties.Interval > 6)
            {
                Interval = 6;
            }
            chartLine.Series[indexOfSeries].Points.AddY(Interval);

            chartLine.Series[indexOfSeries].ChartType   = SeriesChartType.Line;
            chartLine.Series[indexOfSeries].BorderWidth = 3;
            chartLine.Series[indexOfSeries].Color       = DicColor[Name];

            double interval = Convert.ToDouble(Properties.Interval) * 1000;

            if (interval >= 0 && interval < 500)
            {
                yData[0]++;
            }
            else if (interval >= 500 && interval < 1000)
            {
                yData[1]++;
            }
            else if (interval >= 1000 && interval < 2400)
            {
                yData[2]++;
            }
            else
            {
                yData[3]++;
            }
            if ((DateTime.Now - countInterval).TotalMilliseconds >= 10000)
            {
                chartPie.Series[0]["PieLabelStyle"] = "Outside";
                chartPie.Series[0]["PieLineColor"]  = "Black";
                chartPie.Series[0].Points.DataBindXY(xData, yData);
            }
            //Thread.Sleep(0);
        }
示例#14
0
 private void SaveToPcap(PacketProperties Properties)      //修改林庆庆
 {
     CBTCDataCache.Add(Properties);
 }
示例#15
0
 private void SaveToPcap_Signaling(PacketProperties Properties)      //修改林庆庆
 {
     LTEDataCache.Add(Properties);
 }
示例#16
0
 private void SaveToPcap(PacketProperties Properties)
 {
     CatchSocket.TemporaryStorage.Add(Properties);
 }
示例#17
0
 public HandlePacket(byte[] buf, int len)
 {
     PacketProperties             = new PacketProperties(len);
     PacketProperties.CaptureTime = DateTime.Now;
     Unpack(buf, len);
 }
示例#18
0
 private void SaveToShowStorage(PacketProperties properties)
 {
     ShowThread.ShowStorate.Add(properties);
 }