Ejemplo n.º 1
0
        private void SendPacketsToPorts(ushort from, ushort to, PacketCommunicator communicator)
        {
            const int PacketsBufferSize = 102400;

            using (PacketSendBuffer buffer = new PacketSendBuffer(PacketsBufferSize))
            {
                for (ushort port = from; port <= to; port++)
                {
                    Packet packet = TcpPacketFactory.CreateSynPacketFor(this.options, port);
                    buffer.Enqueue(packet);
                }
                communicator.Transmit(buffer, true);
            }
        }
Ejemplo n.º 2
0
        private void ReceivePackets(object arg)
        {
            CancellationToken ct = (CancellationToken)arg;

            using (PacketCommunicator communicator = options.Device.Open(65535, PacketDeviceOpenAttributes.Promiscuous | PacketDeviceOpenAttributes.NoCaptureLocal, 100))
            {
                communicator.SetFilter("tcp and src " + options.TargetIP + " and dst " + options.SourceIP);

                while (true)
                {
                    if (ct.IsCancellationRequested)
                    {
                        return;
                    }

                    Packet responce;
                    PacketCommunicatorReceiveResult result = communicator.ReceivePacket(out responce);

                    if (result == PacketCommunicatorReceiveResult.Ok)
                    {
                        PortInfo info      = ParsePortInfo(responce);
                        Packet   rstPacket = TcpPacketFactory.CreateRstPacketFor(this.options, info.Number);
                        communicator.SendPacket(rstPacket);

                        if (scanResults.Add(info))
                        {
                            Console.WriteLine(info.ToString());
                        }

                        int totalPorts = options.EndPort - options.StartPort;
                        if (scanResults.Count == totalPorts)
                        {
                            break;
                        }
                    }
                }
            }
        }