示例#1
0
        /// <summary>
        /// Sends packet by calling core functions
        /// </summary>
        /// <param name="packet">Packet to send</param>
        /// <param name="countToSend">Count to send</param>
        /// <param name="timeToWaitBeforeNextPacketToSend">Time to wait until sending next packet in milliseconds</param>
        public void SendPacket(INewPacket packet, int countToSend = 1, int timeToWaitBeforeNextPacketToSend = 0)
        {
            if (packet is null)
            {
                throw new ArgumentNullException(nameof(packet));
            }

            if (_allDevices == null ||
                _allDevices.Count == 0)
            {
                throw new InvalidOperationException("No devices found on local machine to send packets with");
            }

            int          userChosenDevice = LetUserChooseInterfaceBeforeWorkingWithPackets();
            PacketDevice selectedDevice   = _allDevices[userChosenDevice - 1];

            using (PacketCommunicator communicator = selectedDevice.Open(65535,
                                                                         PacketDeviceOpenAttributes.NoCaptureLocal,
                                                                         1000))
            {
                for (uint i = 0; i < countToSend; i++)
                {
                    communicator.SendPacket(packet.BuildPacket(true, i));
                    _userExperience.UserTextDisplayer.PrintText($"Sended packet nr {i + 1}...");
                    PauseBeforeSendingPacket(timeToWaitBeforeNextPacketToSend);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Starts program core logic, goes through all steps, one by one
        /// </summary>
        /// <param name="inputData">User input data to work with during logic</param>
        public void ProcessLogic(UserInputData inputData)
        {
            if (inputData == null)
            {
                throw new ArgumentNullException(nameof(inputData));
            }

            if (inputData.IsSendPacket &&
                !inputData.IsInterceptAndForward)
            {
                Packet packet = _fileHandler.TryOpenUserPacketFromFile(inputData.PathToFile);
                if (packet == null)
                {
                    throw new InvalidOperationException(nameof(packet) + " was null");
                }

                INewPacket customPacket = _packetManager.GetPacketByProtocol(packet.Ethernet.IpV4.Protocol).ExtractLayers(packet);
                if (inputData.IsModifyPacket)
                {
                    customPacket.ModifyLayers();
                }

                _packetManager.SendPacket(customPacket, inputData.PacketCountToSend, inputData.TimeToWaitUntilNextPacketWillBeSended);

                if (inputData.IsUserWantsToSavePacket)
                {
                    _fileHandler.TrySaveOnePacketToDisk(customPacket.BuildPacket(false));
                }
            }

            if (inputData.IsInterceptAndForward)
            {
                _packetManager.InterceptAndForwardPackets(inputData);
            }
        }