Exemplo n.º 1
0
        // ReSharper disable once InconsistentNaming
        /// <summary>
        /// Determine which ports are open on a certain address using a TCP and UDP Client
        /// </summary>
        /// <param name="address">The IP address that needs to be scanned</param>
        /// <param name="startPort">The starting point of ports that needs to be scanned</param>
        /// <param name="stopPort">The final port in a range of ports that needs to be scanned</param>
        /// <param name="timeout">The amount of time before a connection times out</param>
        /// <param name="scanOperation">The ScanInformation object containing information regarding this scan</param>
        /// <returns>A list of LvCheck objects containing information regarding the ports and address that were scanned</returns>
        // ReSharper disable once IdentifierTypo
        internal static void CheckTCPUDP(string address, int startPort, int stopPort, int timeout, ScanOperation scanOperation)
        {
            for (int i = startPort; i <= stopPort; i++)
            {
                if (scanOperation.IsCancelled)
                {
                    break;
                }

                CheckTCP(address, i, i, timeout, scanOperation, false);
                CheckUDP(address, i, i, timeout, scanOperation, false);

                scanOperation.Progress.Report(1);
            }
            scanOperation.ScanCompletedEvent?.Invoke();
        }
Exemplo n.º 2
0
        // ReSharper disable once InconsistentNaming
        /// <summary>
        /// Determine which ports are open on a certain address using an UDP Client
        /// </summary>
        /// <param name="address">The IP address that needs to be scanned</param>
        /// <param name="startPort">The starting point of ports that needs to be scanned</param>
        /// <param name="stopPort">The final port in a range of ports that needs to be scanned</param>
        /// <param name="timeout">The amount of time before the connection times out</param>
        /// <param name="scanOperation">The ScanInformation object containing information regarding this scan</param>
        /// <param name="reportProgress">A boolean to represent whether this method should report the current progress or not</param>
        internal static void CheckUDP(string address, int startPort, int stopPort, int timeout, ScanOperation scanOperation, bool reportProgress)
        {
            for (int i = startPort; i <= stopPort; i++)
            {
                if (scanOperation.IsCancelled)
                {
                    break;
                }

                LvCheck check = new LvCheck
                {
                    Address     = address,
                    Port        = i,
                    HostName    = GetMachineNameFromIpAddress(address),
                    Type        = "UDP",
                    Description = IsUdpOpen(address, i, timeout) ? "Open" : "Closed",
                    ScanDate    = DateTime.Now.ToString(CultureInfo.CurrentCulture)
                };

                if (reportProgress)
                {
                    scanOperation.Progress.Report(1);
                }
                scanOperation.ItemProgress.Report(check);
            }

            if (reportProgress)
            {
                scanOperation.ScanCompletedEvent?.Invoke();
            }
        }
        // ReSharper disable once InconsistentNaming
        /// <summary>
        /// Determine which ports are open on a certain address using a TCP and UDP Client
        /// </summary>
        /// <param name="address">The IP address that needs to be scanned</param>
        /// <param name="startPort">The starting point of ports that needs to be scanned</param>
        /// <param name="stopPort">The final port in a range of ports that needs to be scanned</param>
        /// <param name="timeout">The amount of time before a connection times out</param>
        /// <param name="scanOperation">The ScanInformation object containing information regarding this scan</param>
        /// <returns>A list of LvCheck objects containing information regarding the ports and address that were scanned</returns>
        // ReSharper disable once IdentifierTypo
        internal static List <LvCheck> CheckTCPUDP(string address, int startPort, int stopPort, int timeout, ScanOperation scanOperation)
        {
            List <LvCheck> lv = new List <LvCheck>();

            for (int i = startPort; i <= stopPort; i++)
            {
                if (scanOperation.IsCancelled)
                {
                    break;
                }

                lv.AddRange(CheckTCP(address, i, i, timeout, scanOperation, false));
                lv.AddRange(CheckUDP(address, i, i, timeout, scanOperation, false));

                scanOperation.Progress.Report(1);
            }
            scanOperation.ScanCompletedEvent?.Invoke();
            return(lv);
        }