Ejemplo n.º 1
0
        /// <summary>
        /// Prints basic header fields
        /// </summary>
        /// <param name="header"></param>
        public void Print(IHeader header)
        {
            TCPHeader newHeader = header as TCPHeader;

            Console.WriteLine(string.Format("Window Size\tSource Port\tDestination Port\tUrgent Pointer"));
            Console.WriteLine(string.Format("    {0}\t{1}\t{2}\t{3}",
                                            newHeader.WindowSize, newHeader.SourcePort, newHeader.DestPort, newHeader.UrgentPointer));
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="header"></param>
 protected override void Print(params IHeader[] header)
 {
     if (globalFilter == FilterType.All)
     {
         var       ipHeader = header[0] as IPHeader;
         TCPHeader tcpHeader;
         UDPHeader udpHeader;
         if (header[1] is TCPHeader)
         {
             tcpHeader = header[1] as TCPHeader;
             Console.WriteLine(string.Format("{0}\t{1}:{2}\t\t{3}:{4}",
                                             ipHeader.Protocol,
                                             ipHeader.SourceIP, tcpHeader.SourcePort,
                                             ipHeader.DestIP, tcpHeader.DestPort));
         }
         else if (header[1] is UDPHeader)
         {
             udpHeader = header[1] as UDPHeader;
             Console.WriteLine(string.Format("{0}\t{1}:{2}\t\t{3}:{4}",
                                             ipHeader.Protocol,
                                             ipHeader.SourceIP, udpHeader.SourcePort,
                                             ipHeader.DestIP, udpHeader.DestPort));
         }
     }
     else if (globalFilter == FilterType.TCP)
     {
         var ipHeader = header[0] as IPHeader;
         if (ipHeader.Protocol == ProtocolType.Tcp)
         {
             TCPHeader tcpHeader = header[1] as TCPHeader;
             Console.WriteLine(string.Format("{0}\t{1}:{2}\t\t{3}:{4}",
                                             ipHeader.Protocol,
                                             ipHeader.SourceIP, tcpHeader.SourcePort,
                                             ipHeader.DestIP, tcpHeader.DestPort));
         }
     }
     else if (globalFilter == FilterType.UDP)
     {
         var ipHeader = header[0] as IPHeader;
         if (ipHeader.Protocol == ProtocolType.Udp)
         {
             UDPHeader udpHeader = header[1] as UDPHeader;
             Console.WriteLine(string.Format("{0}\t{1}:{2}\t\t{3}:{4}",
                                             ipHeader.Protocol,
                                             ipHeader.SourceIP, udpHeader.SourcePort,
                                             ipHeader.DestIP, udpHeader.DestPort));
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Parses packets
        /// </summary>
        /// <param name="protocol"></param>
        /// <param name="flag"></param>
        protected virtual void ParsePacket(IPHeader protocol, FilterType filter)
        {
            try
            {
                IHeader header;
                switch (filter)
                {
                case FilterType.All:
                    if (protocol.Protocol == ProtocolType.Tcp)
                    {
                        header = new TCPHeader(protocol.Data, Convert.ToInt32(protocol.MessageLength));
                    }
                    else
                    {
                        header = new UDPHeader(protocol.Data, Convert.ToInt32(protocol.MessageLength));
                    }
                    Print(protocol, header);

                    break;

                case FilterType.TCP:

                    if (protocol.Protocol == ProtocolType.Tcp)
                    {
                        header = new TCPHeader(protocol.Data, Convert.ToInt32(protocol.MessageLength));
                        Print(protocol, header);
                    }

                    break;

                case FilterType.UDP:

                    if (protocol.Protocol == ProtocolType.Udp)
                    {
                        header = new UDPHeader(protocol.Data, Convert.ToInt32(protocol.MessageLength));
                        Print(protocol, header);
                    }

                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.StackTrace + " | " + ex.Message);
            }
        }