Пример #1
0
        private void AnalyzeTCP(Packet p)
        {
            if (!(p.PayloadPacket.PayloadPacket is TcpPacket))
                return;

            EthernetPacket ethernet = (EthernetPacket)p;
            IpPacket ip = (IpPacket)p.PayloadPacket;
            TcpPacket tcp = (TcpPacket)p.PayloadPacket.PayloadPacket;
            Neighbor neighbor = null;

            if (tcp.Syn && tcp.Ack)
            {
                neighbor = Program.CurrentProject.data.GetNeighbor(ethernet.SourceHwAddress);
                if (neighbor == null)
                    return;

                if (neighbor.ExistsIP(ip.SourceAddress))
                {
                    Port port = new Port(tcp.SourcePort, Protocol.TCP, ip.SourceAddress);
                    if (!(neighbor.ExistsPort(port)))
                    {
                        neighbor.AddPort(port);
                        Program.CurrentProject.data.AddNeighbor(neighbor);
                    }
                }
                else
                    return;
            }
        }
Пример #2
0
        public void AddPort(Port port)
        {
            if (ExistsPort(port))
                return;

            ports.Add(port);
        }
Пример #3
0
        public bool ExistsPort(Port port)
        {
            foreach (Port p in ports)
            {
                if (p.port == port.port && p.protocol == port.protocol && p.ip.Equals(port.ip))
                    return true;
            }

            return false;
        }