コード例 #1
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();
            }
        }
コード例 #2
0
        /// <summary>
        /// Export the ListView items in plain text format to the FileSystem
        /// </summary>
        /// <param name="path">The path where the scan result should be saved</param>
        /// <param name="lvPorts">The ListView control containing all the LvCheck items</param>
        private static void SaveAsText(string path, ItemsControl lvPorts)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Advanced PortChecker - " + DateTime.Now);
            for (int i = 0; i < lvPorts.Items.Count; i++)
            {
                LvCheck l = (LvCheck)lvPorts.Items[i];
                if (i == lvPorts.Items.Count - 1)
                {
                    sb.Append(l.Address + "\t" + l.Port + "\t" + l.HostName + "\t" + l.Type + "\t" + l.Description + "\t" + l.ScanDate);
                }
                else
                {
                    sb.AppendLine(l.Address + "\t" + l.Port + "\t" + l.HostName + "\t" + l.Type + "\t" + l.Description + "\t" + l.ScanDate);
                }
            }
            Write(path, sb.ToString());
        }