예제 #1
0
        static public void ConvertReceivedData(byte[] buffer, int iReceived)
        {
            if (buffer.Length > 0 && iReceived != 0)
            {
                //getting IP header and data information
                PacketIP ipPacket = new PacketIP(buffer, iReceived);

                // this string used as a key in the buffer
                string strKey = _decPackagesReceived.ToString();   // Guid.NewGuid().ToString();

                //searching which uperlevel protocol contain IP packet
                System.Threading.Thread.Sleep(75);

                string _ipsource = ipPacket.SourceAddress.ToString();
                string _ipdest   = ipPacket.DestinationAddress.ToString();


                switch (ipPacket.Protocol)
                {
                case "TCP":
                {
                    // Console.WriteLine("------------------------------");
                    Console.WriteLine(" ");
                    //if IP contains TCP creating new TCPData object
                    //and assigning all TCP fields
                    PacketTCP tcpPacket = new PacketTCP(ipPacket.Data, ipPacket.MessageLength);
                    if (tcpPacket.DestinationPort != "80" & tcpPacket.SourcePort != "80")
                    {
                        //creating new PacketInfo object to fill the buffer
                        PacketInfo pkgInfo = new PacketInfo(ipPacket, tcpPacket);

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write(ipPacket.SourceAddress.ToString() + ":");
                        Console.Write(tcpPacket.SourcePort.ToString());
                        Console.ForegroundColor = ConsoleColor.Gray;
                        Console.Write(" -> ");
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.Write(ipPacket.DestinationAddress.ToString() + ":");
                        Console.Write(tcpPacket.DestinationPort + " Protocol: ");
                        Console.Write(ipPacket.Protocol + " Boyut: ");

                        Console.Write(ipPacket.TotalLength + " ");
                        if (_datak)
                        {
                            string yazi = BitConverter.ToString(tcpPacket.Data);

                            yazi = yazi.Replace("-", "");
                            yazi = yazi.Replace("0", "");
                            Console.WriteLine(" ");
                            Console.WriteLine(yazi);
                            _wtdata.WriteLine("\r\n" + yazi);
                            _wtdata.Flush();
                        }

                        Console.WriteLine(" ");
                        Console.WriteLine("------------------------------");
                    }
                }
                break;

                case "UDP":
                {
                    Console.WriteLine("------------------------------");
                    Console.WriteLine(" ");
                    PacketUdp  udpPacket = new PacketUdp(ipPacket.Data, ipPacket.MessageLength);
                    PacketInfo pkgInfo   = new PacketInfo(ipPacket, udpPacket);
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write(ipPacket.SourceAddress.ToString() + ":");
                    Console.Write(udpPacket.SourcePort.ToString());
                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.Write(" -> ");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write(ipPacket.DestinationAddress.ToString() + ":");
                    Console.Write(udpPacket.DestinationPort + " Protocol: ");
                    Console.Write(ipPacket.Protocol + " Boyut: ");
                    Console.Write(ipPacket.TotalLength + " ");
                    Console.WriteLine(" ");
                    if (_datak)
                    {
                        string yazi = Encoding.UTF8.GetString(udpPacket.Data);
                        yazi = yazi.Replace("\0", "");
                        Console.WriteLine(" ");
                        Console.WriteLine(yazi);
                        _wudata.WriteLine(DateTime.Now.ToString() + ":" + "\r\n" + yazi);
                        _wudata.Flush();
                    }
                    Console.WriteLine("------------------------------");
                } break;

                case "ICMP":
                {
                    PacketIcmp icmpPacket = new PacketIcmp(ipPacket.Data, ipPacket.MessageLength);
                    PacketInfo pkgInfo    = new PacketInfo(ipPacket, icmpPacket);
                    Console.WriteLine("------------------------------");
                    Console.WriteLine(" ");

                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write(ipPacket.SourceAddress.ToString() + ":");

                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.Write(" -> ");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write(ipPacket.DestinationAddress.ToString() + ":");

                    Console.Write(ipPacket.Protocol + " Boyut: ");
                    Console.Write(ipPacket.TotalLength + " ");
                    Console.WriteLine(" ");
                    Console.WriteLine("------------------------------");
                } break;

                case "IGMP":
                {
                    PacketIgmp igmpPacket = new PacketIgmp(ipPacket.Data, ipPacket.MessageLength);
                    PacketInfo pkgInfo    = new PacketInfo(ipPacket, igmpPacket);
                    Console.WriteLine("------------------------------");
                    Console.WriteLine(" ");

                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write(ipPacket.SourceAddress.ToString() + ":");

                    Console.ForegroundColor = ConsoleColor.Gray;
                    Console.Write(" -> ");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write(ipPacket.DestinationAddress.ToString() + ":");

                    Console.Write(ipPacket.Protocol + " Boyut: ");
                    Console.Write(ipPacket.TotalLength + " ");
                    Console.WriteLine(" ");
                    Console.WriteLine("------------------------------");
                } break;
                }
            }
        }
예제 #2
0
 public PacketInfo(PacketIP ip, PacketIgmp igmp)
 {
     _ip   = ip;
     _igmp = igmp;
 }
예제 #3
0
 public PacketInfo(PacketIP ip, PacketIcmp icmp)
 {
     _ip   = ip;
     _icmp = icmp;
 }
예제 #4
0
 public PacketInfo(PacketIP ip, PacketUdp udp)
 {
     _ip  = ip;
     _udp = udp;
 }
예제 #5
0
 public PacketInfo(PacketIP ip, PacketTCP tcp)
 {
     _ip  = ip;
     _tcp = tcp;
 }
예제 #6
0
 public PacketInfo(PacketIP ip)
 {
     _ip = ip;
 }