Esempio n. 1
0
        private void I_OnPacketArrival(object sender, CaptureEventArgs e)
        {
            int           len      = 0;
            TCPUDP        protocol = TCPUDP.TCP;
            PacketAddress address  = Tool.GetPacketAddressFromRowPacket(e.Packet, ref len, ref protocol);

            if (address != null && len != 0)
            {
                PacketFlow packetFlow = networkStructure.GetPacketFlow(address);
                packetFlow.protocol = protocol;
                uploadDownloadMap.AddPacket(packetFlow, len);
            }
        }
Esempio n. 2
0
 public Port(uint ip, ushort port, TCPUDP protocol)
 {
     this.ip       = ip;
     this.port     = port;
     this.protocol = protocol;
 }
 /// <summary>
 /// Get the packet Information from <see cref="RawCapture"/>
 /// </summary>
 /// <param name="rawCapture">The raw captured packet</param>
 /// <param name="len">Get the length of bytes of the packet</param>
 /// <param name="protocol">Get the tansport protocol of the packet</param>
 /// <returns>The Addresses of the packet. Null if the packet has error, or it's not IP packet, or It's IPV6.</returns>
 public static PacketAddress GetPacketAddressFromRowPacket(RawCapture rawCapture, ref int len, ref TCPUDP protocol)
 {
     try
     {
         Packet   p        = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data);
         IpPacket ipPacket = (IpPacket)p.Extract(typeof(IpPacket));
         if (ipPacket != null)
         {
             len = ipPacket.PayloadLength;
             IPAddress sourceAddress, destinationAddress;
             sourceAddress      = ipPacket.SourceAddress;
             destinationAddress = ipPacket.DestinationAddress;
             if (sourceAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork &&
                 destinationAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
             {
                 IPProtocolType type = ipPacket.NextHeader;
                 if (type == IPProtocolType.TCP)
                 {
                     TcpPacket tcpPacket = (TcpPacket)ipPacket.Extract(typeof(TcpPacket));
                     if (tcpPacket != null)
                     {
                         protocol = TCPUDP.TCP;
                         return(new PacketAddress(sourceAddress, tcpPacket.SourcePort, destinationAddress, tcpPacket.DestinationPort));
                     }
                 }
                 else if (type == IPProtocolType.UDP)
                 {
                     UdpPacket udpPacket = (UdpPacket)ipPacket.Extract(typeof(UdpPacket));
                     if (udpPacket != null)
                     {
                         protocol = TCPUDP.UDP;
                         return(new PacketAddress(sourceAddress, udpPacket.SourcePort, destinationAddress, udpPacket.DestinationPort));
                     }
                 }
             }
         }
         return(null);
     }
     catch (Exception)
     {
         Console.WriteLine("Packet Error");
         //Console.WriteLine(e.Message + "\n" + e.StackTrace);
         return(null);
     }
 }