diff --git a/.claude/skills/feature-review/references/conventions.md b/.claude/skills/feature-review/references/conventions.md
index adbd8058f0..48cc3f2a29 100644
--- a/.claude/skills/feature-review/references/conventions.md
+++ b/.claude/skills/feature-review/references/conventions.md
@@ -47,7 +47,8 @@ Reference: `PortScannerViewModel`, `IPScannerViewModel`.
- Inputs are added to a history (`ListHelper.Modify`, limited by
`GlobalStaticConfiguration.General_HistoryListEntries`). An editable `ComboBox` also selects a history entry that
matches the typed text: extra values restored from the history (e.g. ports of a host) are only applied when the entry
- was picked from the list (click, or arrow keys + `Enter`), not on `SelectionChanged` alone.
+ was picked from the list (click, or arrow keys + `Enter`; `ComboBoxPickHelper.OnItemPicked`), not on `SelectionChanged`
+ alone. Reference: Ping Monitor (protocol + port), Port Scanner (ports) with `HostHistoryOptions`.
- Very large inputs (e.g. a `/16`) need a confirmation above a threshold and are refused above a limit, with a message,
instead of freezing the application (reference: Ping Monitor, 256 / 4,096 hosts).
- Continuous actions (Ping Monitor, auto refresh, live widgets) run as async loops, not one blocked thread per item. A
@@ -270,11 +271,19 @@ Duplicated code often re-implements one of these. A refactoring proposal should
adds a new helper. Check the class for the exact methods.
- Host and port input: `HostRangeHelper` (Models: `CreateListFromInput`, `GetHostCount`, `ResolveAsync` with `!`
- exclusions - IP Scanner, Port Scanner, Ping Monitor), `PortRangeHelper` (Utilities), validators in
+ exclusions - IP Scanner, Port Scanner, Ping Monitor), `PortRangeHelper` (Utilities), `PingMonitorPortProfile` (Models:
+ one port as `443/tcp`, parse, resolve a port profile, `Encode` / `Decode` of the reference), validators in
`NETworkManager.Validators` (one per input format, used by tool, profile dialog and run command).
+- Input drop-downs: `InputSuggestions` (history + profiles of the settings in one grouped list, `Tab` completion, e.g.
+ `ForPortScannerPorts`, `ForPingMonitorPort`, `ForDNSLookupDNSServers`).
+- History: `ListHelper.Modify` (the list), `HostHistoryOptions` (Utilities: `Set` / `Find` / `Prune` the values a host
+ of the history was last used with; pruned in `SettingsManager.Save`), `ComboBoxPickHelper` (Utilities.WPF: an entry
+ picked from the list, not typed text).
+- Notifications: `NotificationManager` (`FormatChanges`: one notification for several changes, `(+N more)`) with
+ `NotificationLine` (`JoinText`, `FormatHost`). Reference: Ping Monitor, IP Scanner, Port Scanner.
- Addresses and names: `IPAddressHelper` (compare / sort, private range, scope id), `MACAddressHelper` (format,
compare), `DNSClientHelper` / `DNSClient` (resolve A / AAAA / PTR with the app's DNS settings), `RegexHelper`.
-- Lists and texts: `ListHelper.Modify` (history), `PlaceholderHelper` (`{{Name}}` placeholders), `DateTimeHelper`,
+- Lists and texts: `PlaceholderHelper` (`{{Name}}` placeholders), `DateTimeHelper`,
`ClipboardHelper`, `DialogHelper` (confirmations, `FormatItemList`).
- WPF: `BindingProxy`, `DataGridHelper`, `SearchTextBoxHelper`, `PermissionToolTipHelper` (Utilities.WPF),
`ObservableRangeCollection` (Controls), converters in `NETworkManager.Converters` (e.g. `PendingToStringConverter`),
diff --git a/Source/NETworkManager.Converters/PingMonitorProfileCheckConverter.cs b/Source/NETworkManager.Converters/PingMonitorProfileCheckConverter.cs
new file mode 100644
index 0000000000..6bfc7276e8
--- /dev/null
+++ b/Source/NETworkManager.Converters/PingMonitorProfileCheckConverter.cs
@@ -0,0 +1,35 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+using NETworkManager.Profiles;
+using PingMonitorProfile = NETworkManager.Profiles.Application.PingMonitor;
+
+namespace NETworkManager.Converters;
+
+///
+/// Converts a to its check in the Ping Monitor ("icmp", "22/tcp", "HTTPS · 443/tcp"),
+/// null if the profile and its group don't override the protocol (tooltip of the profile).
+///
+public sealed class PingMonitorProfileCheckConverter : IValueConverter
+{
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ if (value is not ProfileInfo profile)
+ return null;
+
+ try
+ {
+ return PingMonitorProfile.GetCheckText(profile);
+ }
+ catch (Exception)
+ {
+ // Only a tooltip (e.g. the profile file is being switched)
+ return null;
+ }
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+}
diff --git a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs
index 2a5a02ac87..6de355c5da 100644
--- a/Source/NETworkManager.Localization/Resources/Strings.Designer.cs
+++ b/Source/NETworkManager.Localization/Resources/Strings.Designer.cs
@@ -5116,6 +5116,15 @@ public static string EnterValidPort {
}
}
+ ///
+ /// Looks up a localized string similar to Enter a valid port (1 - 65535) or port profile!.
+ ///
+ public static string EnterValidPortOrPortProfile {
+ get {
+ return ResourceManager.GetString("EnterValidPortOrPortProfile", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Enter a valid port and/or port range (1 - 65535)!.
///
@@ -5260,6 +5269,15 @@ public static string ErrorMessage_NameMustNotContainSemicolon {
}
}
+ ///
+ /// Looks up a localized string similar to The name must not be a port (e.g. 443 or 443/tcp)..
+ ///
+ public static string ErrorMessage_PingMonitorPortProfileNameInvalid {
+ get {
+ return ResourceManager.GetString("ErrorMessage_PingMonitorPortProfileNameInvalid", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to The name must not contain ";" and must not be a port or port range..
///
@@ -6383,7 +6401,7 @@ public static string HelpMessage_Animations {
///
///Only the PowerShell consoles configured in the PowerShell settings are modified. Both Windows PowerShell and PWSH (PowerShell 7 and higher) are supported.
///
- ///Click in the upper right corner on the help / documentation button ( [rest of string was truncated]";.
+ ///Click in the upper right corner on the help / documentation button (left [rest of string was truncated]";.
///
public static string HelpMessage_ApplyThemeToPowerShellConsole {
get {
@@ -10727,6 +10745,15 @@ public static string PingMonitorNotification {
}
}
+ ///
+ /// Looks up a localized string similar to The port profile of this profile or its group was not found, the port saved with the profile or group is used. Port profiles are saved in the settings and the profile or group refers to them by an internal ID - if the profile file was shared from another computer, create the port profile and then select it in the profile or group again (edit it)..
+ ///
+ public static string PingMonitorPortProfileOfProfileNotFoundMessage {
+ get {
+ return ResourceManager.GetString("PingMonitorPortProfileOfProfileNotFoundMessage", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to {0} hosts cannot be monitored at once (maximum {1}). Split the input into smaller ranges..
///
@@ -10844,6 +10871,15 @@ public static string PortChange_Opened {
}
}
+ ///
+ /// Looks up a localized string similar to Port closed.
+ ///
+ public static string PortClosed {
+ get {
+ return ResourceManager.GetString("PortClosed", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Port description.
///
@@ -11117,7 +11153,7 @@ public static string Profile {
///
/// Looks up a localized string similar to Profile files are encrypted on disk using AES with a key size of 256 bits and a block size of 128 bits in CBC mode. The encryption key is derived from a master password using Rfc2898DeriveBytes (PBKDF2) with 1,000,000 iterations. At runtime, passwords are stored as SecureString once the profile file is loaded. For some functions, the password must be converted to a normal string and remains unencrypted in memory until the garbage collector cleans them up.
///
- ///First make a backup copy of your profile files be [rest of string was truncated]";.
+ ///First make a backup copy of your profile files befo [rest of string was truncated]";.
///
public static string ProfileEncryptionDisclaimer {
get {
diff --git a/Source/NETworkManager.Localization/Resources/Strings.resx b/Source/NETworkManager.Localization/Resources/Strings.resx
index e0cd7f8828..4d1848e5e7 100644
--- a/Source/NETworkManager.Localization/Resources/Strings.resx
+++ b/Source/NETworkManager.Localization/Resources/Strings.resx
@@ -1586,6 +1586,9 @@ Profile files are not affected!
Enter a valid OID!
+
+ Enter a valid port (1 - 65535) or port profile!
+
Enter a valid port and/or port range (1 - 65535)!
@@ -3116,6 +3119,9 @@ Enable profile file encryption in Settings>Profile to store credentials secur
Device description
+
+ Port closed
+
Port description
@@ -5145,6 +5151,9 @@ Do you want to start the scan?
Enter valid ports, port ranges (1 - 65535) and/or port profiles!
+
+ The name must not be a port (e.g. 443 or 443/tcp).
+
The name must not contain ";" and must not be a port or port range.
@@ -5922,6 +5931,9 @@ Open Windows Settings > Privacy & security > Location and enable acces
Do you want to add the hosts?
+
+ The port profile of this profile or its group was not found, the port saved with the profile or group is used. Port profiles are saved in the settings and the profile or group refers to them by an internal ID - if the profile file was shared from another computer, create the port profile and then select it in the profile or group again (edit it).
+
{0} hosts cannot be monitored at once (maximum {1}). Split the input into smaller ranges.
diff --git a/Source/NETworkManager.Models/Export/ExportManager.PingInfo.cs b/Source/NETworkManager.Models/Export/ExportManager.PingInfo.cs
index 9a7a55ca35..6d22ca5b9e 100644
--- a/Source/NETworkManager.Models/Export/ExportManager.PingInfo.cs
+++ b/Source/NETworkManager.Models/Export/ExportManager.PingInfo.cs
@@ -20,14 +20,31 @@ public static partial class ExportManager
new(nameof(PingInfo.Bytes), x => HasPingReply(x.Status) ? x.Bytes : null)
];
+ ///
+ /// Exported fields of a TCP check of a (no TTL / bytes, the port instead).
+ ///
+ private static readonly ExportField[] PingInfoTCPExportFields =
+ [
+ new(nameof(PingInfo.Timestamp), x => x.Timestamp),
+ new(nameof(PingInfo.IPAddress), x => x.IPAddress),
+ new(nameof(PingInfo.Hostname), x => x.Hostname, true),
+ new(nameof(PingInfo.Port), x => x.Port),
+ new(nameof(PingInfo.Status), x => x.Status),
+ new(nameof(PingInfo.Time), x => HasPingReply(x.Status) ? x.Time : null)
+ ];
+
///
/// Method to export objects from type to a file.
///
/// Path to the export file.
/// Allowed are CSV, XML or JSON.
/// Objects as to export.
- public static void Export(string filePath, ExportFileType fileType, IReadOnlyList collection)
+ /// Method of the checks, selects the exported fields (ICMP by default).
+ public static void Export(string filePath, ExportFileType fileType, IReadOnlyList collection,
+ HostMonitorMethod method = HostMonitorMethod.ICMP)
{
- Export(filePath, fileType, collection, PingInfoExportFields, ApplicationName.PingMonitor);
+ Export(filePath, fileType, collection,
+ method == HostMonitorMethod.TCP ? PingInfoTCPExportFields : PingInfoExportFields,
+ ApplicationName.PingMonitor);
}
}
diff --git a/Source/NETworkManager.Models/Network/HostMonitorMethod.cs b/Source/NETworkManager.Models/Network/HostMonitorMethod.cs
new file mode 100644
index 0000000000..0541f2f24a
--- /dev/null
+++ b/Source/NETworkManager.Models/Network/HostMonitorMethod.cs
@@ -0,0 +1,17 @@
+namespace NETworkManager.Models.Network;
+
+///
+/// How a host is checked by the Ping Monitor.
+///
+public enum HostMonitorMethod
+{
+ ///
+ /// ICMP echo request (ping).
+ ///
+ ICMP,
+
+ ///
+ /// TCP connect to a port (TCP ping), e.g. for hosts that block ICMP.
+ ///
+ TCP
+}
diff --git a/Source/NETworkManager.Models/Network/ICMPHostMonitorProbe.cs b/Source/NETworkManager.Models/Network/ICMPHostMonitorProbe.cs
index 06fd725e5b..ce2675b1ac 100644
--- a/Source/NETworkManager.Models/Network/ICMPHostMonitorProbe.cs
+++ b/Source/NETworkManager.Models/Network/ICMPHostMonitorProbe.cs
@@ -45,8 +45,12 @@ public async Task ProbeAsync(CancellationToken cancellationToken)
var pingReply = await ping.SendPingAsync(_ipAddress, _timeout, _buffer, _options, cancellationToken)
.ConfigureAwait(false);
- return pingReply.Status == IPStatus.Success
+ var pingInfo = pingReply.Status == IPStatus.Success
? PingInfo.FromSuccessfulReply(timestamp, pingReply)
: new PingInfo(timestamp, _ipAddress, pingReply.Status);
+
+ pingInfo.Method = HostMonitorMethod.ICMP;
+
+ return pingInfo;
}
}
diff --git a/Source/NETworkManager.Models/Network/IHostMonitorProbe.cs b/Source/NETworkManager.Models/Network/IHostMonitorProbe.cs
index daec5343ad..d263264b46 100644
--- a/Source/NETworkManager.Models/Network/IHostMonitorProbe.cs
+++ b/Source/NETworkManager.Models/Network/IHostMonitorProbe.cs
@@ -8,8 +8,8 @@ namespace NETworkManager.Models.Network;
/// once per interval, so a probe only has to check the host once.
///
///
-/// Only ICMP () exists so far. Further methods (e.g. TCP connect, HTTP) are
-/// planned; they return the same result type, its status is the
+/// ICMP () and TCP connect () exist; HTTP(S) is
+/// planned. They return the same result type, its status is the
/// that matches the outcome (e.g. Success, TimedOut).
///
public interface IHostMonitorProbe
diff --git a/Source/NETworkManager.Models/Network/PingInfo.cs b/Source/NETworkManager.Models/Network/PingInfo.cs
index e3c5c5bcfc..900674ca25 100644
--- a/Source/NETworkManager.Models/Network/PingInfo.cs
+++ b/Source/NETworkManager.Models/Network/PingInfo.cs
@@ -173,6 +173,16 @@ internal static PingInfo FromSuccessfulReply(DateTime timestamp, PingReply pingR
///
public IPStatus Status { get; set; }
+ ///
+ /// Method of the check (Ping Monitor), null for results of other features.
+ ///
+ public HostMonitorMethod? Method { get; set; }
+
+ ///
+ /// Port of a TCP check (Ping Monitor), null for other methods.
+ ///
+ public int? Port { get; set; }
+
///
/// IP address as an integer.
///
diff --git a/Source/NETworkManager.Models/Network/PingMonitorHostHelper.cs b/Source/NETworkManager.Models/Network/PingMonitorHostHelper.cs
index f3d81ea8a4..2ae96466fa 100644
--- a/Source/NETworkManager.Models/Network/PingMonitorHostHelper.cs
+++ b/Source/NETworkManager.Models/Network/PingMonitorHostHelper.cs
@@ -14,9 +14,6 @@ public static class PingMonitorHostHelper
/// group they are added to). Several entries of the input for the same IP address (e.g. different hostnames, see
/// ) are kept.
///
- ///
- /// With further check methods (e.g. TCP, HTTP), the method and its port / URL become part of the key.
- ///
/// Hosts to add.
/// IP addresses already monitored in the group.
/// Hosts to add and hosts that are already monitored, in the order of .
@@ -24,13 +21,35 @@ public static (List<(IPAddress ipAddress, string hostname)> hostsToAdd,
List<(IPAddress ipAddress, string hostname)> alreadyMonitored) SplitAlreadyMonitored(
IEnumerable<(IPAddress ipAddress, string hostname)> hosts, IEnumerable monitoredIPAddresses)
{
- var monitored = monitoredIPAddresses.ToHashSet();
+ var (hostsToAdd, alreadyMonitored) =
+ SplitAlreadyMonitored(hosts, [0], monitoredIPAddresses.Select(x => (x, 0)));
- var hostsToAdd = new List<(IPAddress ipAddress, string hostname)>();
- var alreadyMonitored = new List<(IPAddress ipAddress, string hostname)>();
+ return (hostsToAdd.Select(x => x.host).ToList(), alreadyMonitored.Select(x => x.host).ToList());
+ }
+
+ ///
+ /// Splits the hosts and ports to add (every host with every port, e.g. "Webserver" = 80 and 443 are two hosts
+ /// per IP address) into the new ones and the ones that are already monitored with the same method in the group
+ /// (key: IP address and port; port 0 for ICMP). Several entries of the input for the same IP address are kept.
+ ///
+ /// Hosts to add.
+ /// Ports of the TCP checks, [0] for ICMP.
+ /// IP addresses and ports already monitored with the method in the group.
+ /// Hosts and ports to add and already monitored, by host (in the order of ), then
+ /// by port (in the order of ).
+ public static (List<((IPAddress ipAddress, string hostname) host, int port)> hostsToAdd,
+ List<((IPAddress ipAddress, string hostname) host, int port)> alreadyMonitored) SplitAlreadyMonitored(
+ IEnumerable<(IPAddress ipAddress, string hostname)> hosts, IReadOnlyList ports,
+ IEnumerable<(IPAddress ipAddress, int port)> monitored)
+ {
+ var monitoredSet = monitored.ToHashSet();
+
+ var hostsToAdd = new List<((IPAddress ipAddress, string hostname) host, int port)>();
+ var alreadyMonitored = new List<((IPAddress ipAddress, string hostname) host, int port)>();
foreach (var host in hosts)
- (monitored.Contains(host.ipAddress) ? alreadyMonitored : hostsToAdd).Add(host);
+ foreach (var port in ports)
+ (monitoredSet.Contains((host.ipAddress, port)) ? alreadyMonitored : hostsToAdd).Add((host, port));
return (hostsToAdd, alreadyMonitored);
}
diff --git a/Source/NETworkManager.Models/Network/PingMonitorHostHistoryInfo.cs b/Source/NETworkManager.Models/Network/PingMonitorHostHistoryInfo.cs
new file mode 100644
index 0000000000..7d345ae7e1
--- /dev/null
+++ b/Source/NETworkManager.Models/Network/PingMonitorHostHistoryInfo.cs
@@ -0,0 +1,43 @@
+using NETworkManager.Utilities;
+
+namespace NETworkManager.Models.Network;
+
+///
+/// Protocol and port a host of the history of the Ping Monitor was last added with (restored when the host is
+/// selected from the history), see .
+///
+public class PingMonitorHostHistoryInfo : IHostHistoryEntry
+{
+ ///
+ /// Creates an empty entry (serializer).
+ ///
+ public PingMonitorHostHistoryInfo()
+ {
+ }
+
+ ///
+ /// Creates an entry.
+ ///
+ /// Host as in the history.
+ /// Protocol of the checks.
+ /// Port input of a TCP check as entered ("443", "443/tcp" or a port profile), null for ICMP.
+ public PingMonitorHostHistoryInfo(string host, HostMonitorMethod method, string port)
+ {
+ Host = host;
+ Method = method;
+ Port = port;
+ }
+
+ ///
+ public string Host { get; set; }
+
+ ///
+ /// Protocol of the checks.
+ ///
+ public HostMonitorMethod Method { get; set; }
+
+ ///
+ /// Port input of a TCP check as entered ("443", "443/tcp" or the name of a port profile), null for ICMP.
+ ///
+ public string Port { get; set; }
+}
diff --git a/Source/NETworkManager.Models/Network/PingMonitorPortProfile.cs b/Source/NETworkManager.Models/Network/PingMonitorPortProfile.cs
new file mode 100644
index 0000000000..783461f8e8
--- /dev/null
+++ b/Source/NETworkManager.Models/Network/PingMonitorPortProfile.cs
@@ -0,0 +1,184 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using NETworkManager.Utilities;
+
+namespace NETworkManager.Models.Network;
+
+///
+/// Port of the TCP checks of the Ping Monitor: a port ("443" or "443/tcp") or the name of a port profile (e.g.
+/// "HTTPS"), see . One port per host - the Ping Monitor is not a port
+/// scanner, so there are no lists or port ranges.
+///
+public static class PingMonitorPortProfile
+{
+ ///
+ /// Suffix of a port of a TCP check, e.g. "443/tcp" (like the tag of a host and the notification lines).
+ ///
+ private const string TcpSuffix = "/tcp";
+
+ ///
+ /// Formats a port of a TCP check, e.g. "443/tcp".
+ ///
+ /// Port.
+ /// Port with the protocol.
+ public static string Format(int port)
+ {
+ return port.ToString(CultureInfo.InvariantCulture) + TcpSuffix;
+ }
+
+ ///
+ /// Parses a port: "443" or "443/tcp" (case-insensitive, leading / trailing spaces are ignored).
+ ///
+ /// Text to parse.
+ /// Port if the text is a valid port.
+ /// True if the text is a port (1 - 65535).
+ public static bool TryParsePort(string text, out int port)
+ {
+ port = 0;
+
+ if (string.IsNullOrWhiteSpace(text))
+ return false;
+
+ var value = text.Trim();
+
+ if (value.EndsWith(TcpSuffix, StringComparison.OrdinalIgnoreCase))
+ value = value[..^TcpSuffix.Length].TrimEnd();
+
+ return int.TryParse(value, NumberStyles.None, CultureInfo.InvariantCulture, out port) &&
+ PortRangeHelper.IsValidPort(port);
+ }
+
+ ///
+ /// Finds a port profile by its name (case-insensitive, leading / trailing spaces are ignored).
+ ///
+ /// Port profiles.
+ /// Name of the port profile.
+ /// Port profile, or null if there is none with the name.
+ public static PingMonitorPortProfileInfo FindByName(IEnumerable portProfiles,
+ string name)
+ {
+ return NamedReferenceInput.FindByName(portProfiles, name);
+ }
+
+ ///
+ /// Checks if a name can be used for a port profile: the name is entered instead of a port, so it must not be a
+ /// port (e.g. "443" or "443/tcp").
+ ///
+ /// Name to check.
+ /// True if the name can be used.
+ public static bool IsValidName(string name)
+ {
+ return !string.IsNullOrWhiteSpace(name) && !TryParsePort(name, out _);
+ }
+
+ ///
+ /// Resolves the port input: a port or the name of a port profile.
+ ///
+ /// Port input.
+ /// Port profiles.
+ /// Port if the input is valid.
+ /// True if the input is a port or the name of a port profile.
+ public static bool TryResolvePort(string input, IEnumerable portProfiles, out int port)
+ {
+ if (TryParsePort(input, out port))
+ return true;
+
+ // A port profile with an invalid port (e.g. a hand-edited settings file) is no valid input
+ var portProfile = FindByName(portProfiles ?? [], input);
+ port = portProfile is { } profile && PortRangeHelper.IsValidPort(profile.Port) ? profile.Port : 0;
+
+ return port != 0;
+ }
+
+ ///
+ /// Converts a port input (e.g. of a profile or group) to the values that are saved: the port (a port profile
+ /// replaced by its port, used if the port profile can't be found later, e.g. a profile file from another
+ /// computer) and the reference to the port profile (its ID, so it is also found after a rename), like the ports
+ /// of the Port Scanner (see ).
+ ///
+ /// Port input.
+ /// Port profiles.
+ /// Port (0 if the input is not valid) and the reference (null if the input is no port profile).
+ public static (int Port, string PortInput) Encode(string input, IEnumerable portProfiles)
+ {
+ var portProfileList = portProfiles?.ToList() ?? [];
+
+ var port = TryResolvePort(input, portProfileList, out var resolvedPort) ? resolvedPort : 0;
+
+ // A port is never a port profile (see IsValidName); a port profile is referenced by its ID
+ var portProfile = TryParsePort(input, out _) ? null : FindByName(portProfileList, input);
+
+ return (port, portProfile is { } profile && profile.Id != Guid.Empty ? profile.Id.ToString("B") : null);
+ }
+
+ ///
+ /// Converts the saved values (see ) back to the port input: the port profile with its
+ /// current name (also after a rename), or the saved port if the port profile can't be found.
+ ///
+ /// Saved port, 0 if none.
+ /// Saved reference to a port profile.
+ /// Port profiles.
+ /// True if the port profile can't be found.
+ /// Port input (name of the port profile or the port), null if there is none.
+ public static string Decode(int port, string portInput, IEnumerable portProfiles,
+ out bool portProfileNotFound)
+ {
+ portProfileNotFound = false;
+
+ var savedPort = PortRangeHelper.IsValidPort(port) ? port.ToString(CultureInfo.InvariantCulture) : null;
+
+ if (string.IsNullOrEmpty(portInput))
+ return savedPort;
+
+ if (NamedReferenceInput.TryDecodeReferences(portInput, portProfiles ?? [], out var input))
+ return input;
+
+ portProfileNotFound = true;
+
+ return savedPort;
+ }
+
+ ///
+ /// Gets the protocol of a check from its port input, e.g. for the run command (below the input, it can't be
+ /// typed): "icmp" without a port, "tcp" with a port, "tcp (443/tcp)" with a port profile.
+ ///
+ /// Port input, null or empty for ICMP.
+ /// Port profiles.
+ /// Protocol, with the port of a port profile.
+ public static string GetProtocolText(string portInput, IEnumerable portProfiles)
+ {
+ if (string.IsNullOrWhiteSpace(portInput))
+ return "icmp";
+
+ // A port is shown as typed, a port profile with its port; an invalid input is shown by the validation
+ return !TryParsePort(portInput, out _) && TryResolvePort(portInput, portProfiles, out var port)
+ ? $"tcp ({Format(port)})"
+ : "tcp";
+ }
+
+ ///
+ /// Gets the default port profiles: common services that are checked with a TCP connection (no UDP services,
+ /// e.g. NTP).
+ ///
+ /// Port profiles, each with a new ID.
+ public static List GetDefaultList()
+ {
+ return
+ [
+ new("DNS", 53),
+ new("HTTP", 80),
+ new("HTTPS", 443),
+ new("SSH", 22),
+ new("Telnet", 23),
+ new("SMTP", 25),
+ new("LDAP", 389),
+ new("LDAPS", 636),
+ new("SMB", 445),
+ new("RDP", 3389),
+ new("WinRM", 5985),
+ new("WinRM (HTTPS)", 5986)
+ ];
+ }
+}
diff --git a/Source/NETworkManager.Models/Network/PingMonitorPortProfileInfo.cs b/Source/NETworkManager.Models/Network/PingMonitorPortProfileInfo.cs
new file mode 100644
index 0000000000..661a10e95b
--- /dev/null
+++ b/Source/NETworkManager.Models/Network/PingMonitorPortProfileInfo.cs
@@ -0,0 +1,45 @@
+using System;
+
+namespace NETworkManager.Models.Network;
+
+///
+/// Port profile of the Ping Monitor: a named port of the TCP checks (e.g. "HTTPS" = 443/tcp). The Ping Monitor
+/// checks one port per host, so a port profile has one port (other than the port profiles of the Port Scanner).
+///
+public class PingMonitorPortProfileInfo : INamedReference
+{
+ ///
+ /// Creates an empty port profile (serializer).
+ ///
+ public PingMonitorPortProfileInfo()
+ {
+ }
+
+ ///
+ /// Creates a new port profile with a new .
+ ///
+ /// Name of the port profile, e.g. "HTTPS".
+ /// Port, e.g. 443.
+ public PingMonitorPortProfileInfo(string name, int port)
+ {
+ Id = Guid.NewGuid();
+ Name = name;
+ Port = port;
+ }
+
+ ///
+ /// Internal ID of the port profile - profiles and groups reference a port profile by it, so a renamed port
+ /// profile is still found. Kept when the port profile is edited.
+ ///
+ public Guid Id { get; set; }
+
+ ///
+ /// Name of the port profile, e.g. "HTTPS".
+ ///
+ public string Name { get; set; }
+
+ ///
+ /// Port of the TCP check (1 - 65535).
+ ///
+ public int Port { get; set; }
+}
diff --git a/Source/NETworkManager.Models/Network/PortScannerHostHistoryInfo.cs b/Source/NETworkManager.Models/Network/PortScannerHostHistoryInfo.cs
new file mode 100644
index 0000000000..94250c9aed
--- /dev/null
+++ b/Source/NETworkManager.Models/Network/PortScannerHostHistoryInfo.cs
@@ -0,0 +1,36 @@
+using NETworkManager.Utilities;
+
+namespace NETworkManager.Models.Network;
+
+///
+/// Ports a host of the history of the Port Scanner was last scanned with (restored when the host is selected from
+/// the history), see .
+///
+public class PortScannerHostHistoryInfo : IHostHistoryEntry
+{
+ ///
+ /// Creates an empty entry (serializer).
+ ///
+ public PortScannerHostHistoryInfo()
+ {
+ }
+
+ ///
+ /// Creates an entry.
+ ///
+ /// Host as in the history.
+ /// Ports input as entered (ports, port ranges and port profiles, e.g. "Webserver; 8080").
+ public PortScannerHostHistoryInfo(string host, string ports)
+ {
+ Host = host;
+ Ports = ports;
+ }
+
+ ///
+ public string Host { get; set; }
+
+ ///
+ /// Ports input as entered (ports, port ranges and port profiles, e.g. "Webserver; 8080").
+ ///
+ public string Ports { get; set; }
+}
diff --git a/Source/NETworkManager.Models/Network/TCPHostMonitorProbe.cs b/Source/NETworkManager.Models/Network/TCPHostMonitorProbe.cs
new file mode 100644
index 0000000000..c0e0fc7a90
--- /dev/null
+++ b/Source/NETworkManager.Models/Network/TCPHostMonitorProbe.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Diagnostics;
+using System.Net;
+using System.Net.NetworkInformation;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace NETworkManager.Models.Network;
+
+///
+/// Checks a host with one TCP connect to a port per call (TCP ping). An open port is up, a closed port (the host
+/// answered with a reset) is down with , no answer is
+/// .
+///
+public sealed class TCPHostMonitorProbe : IHostMonitorProbe
+{
+ private readonly IPAddress _ipAddress;
+ private readonly int _port;
+ private readonly int _timeout;
+
+ ///
+ /// Creates a new TCP probe.
+ ///
+ /// IP address of the host.
+ /// Port to connect to (1 - 65535).
+ /// Time in milliseconds to wait for the connection.
+ public TCPHostMonitorProbe(IPAddress ipAddress, int port, int timeout)
+ {
+ if (port is < 1 or > 65535)
+ throw new ArgumentOutOfRangeException(nameof(port), port, "The port must be between 1 and 65535.");
+
+ _ipAddress = ipAddress;
+ _port = port;
+ _timeout = timeout;
+ }
+
+ ///
+ public string Name => "TCP";
+
+ ///
+ public async Task ProbeAsync(CancellationToken cancellationToken)
+ {
+ var timestamp = DateTime.Now;
+ var start = Stopwatch.GetTimestamp();
+
+ // One connection request: the monitor repeats the check every wait time, so no retries here
+ var portState = await PortProbe.ProbeAsync(_ipAddress, _port, _timeout, 1, cancellationToken)
+ .ConfigureAwait(false);
+
+ var status = portState switch
+ {
+ PortState.Open => IPStatus.Success,
+ PortState.Closed => IPStatus.DestinationPortUnreachable,
+ _ => IPStatus.TimedOut
+ };
+
+ // Time to connect (only for a successful connect, like the round-trip time of a ping)
+ var time = status == IPStatus.Success
+ ? (long)Stopwatch.GetElapsedTime(start).TotalMilliseconds
+ : 0;
+
+ return new PingInfo(timestamp, _ipAddress, 0, time, status)
+ {
+ Method = HostMonitorMethod.TCP,
+ Port = _port
+ };
+ }
+}
diff --git a/Source/NETworkManager.Models/RunCommand/RunCommandArgument.cs b/Source/NETworkManager.Models/RunCommand/RunCommandArgument.cs
index 57e32b43cd..f1a551c661 100644
--- a/Source/NETworkManager.Models/RunCommand/RunCommandArgument.cs
+++ b/Source/NETworkManager.Models/RunCommand/RunCommandArgument.cs
@@ -11,5 +11,6 @@ public enum RunCommandArgument
DNSServer,
Broadcast,
Subnet,
- Duration
+ Duration,
+ Port
}
diff --git a/Source/NETworkManager.Profiles/Application/PingMonitor.cs b/Source/NETworkManager.Profiles/Application/PingMonitor.cs
new file mode 100644
index 0000000000..7431306ba9
--- /dev/null
+++ b/Source/NETworkManager.Profiles/Application/PingMonitor.cs
@@ -0,0 +1,119 @@
+using System.Collections.Generic;
+using System.Linq;
+using NETworkManager.Models.Network;
+using NETworkManager.Settings;
+
+namespace NETworkManager.Profiles.Application;
+
+public static class PingMonitor
+{
+ ///
+ /// Gets the protocol and port for a profile: its own (if overridden), otherwise the ones of its group (if
+ /// overridden), otherwise none (the protocol and port of the input of the Ping Monitor are used). A port profile
+ /// with its current name (also after a rename); if it can't be found (deleted, or a profile file shared from
+ /// another computer - port profiles are saved in the settings), the port saved with the profile or group.
+ ///
+ /// Profile to get the protocol and port for.
+ /// True if the port profile can't be found.
+ /// Protocol (null if not overridden) and port input (null for ICMP or if not overridden).
+ public static (HostMonitorMethod? Method, string Port) GetMethodAndPort(ProfileInfo profile,
+ out bool portProfileNotFound)
+ {
+ return GetMethodAndPort(profile, FindGroup(profile), SettingsManager.Current.PingMonitor_PortProfiles,
+ out portProfileNotFound);
+ }
+
+ ///
+ /// Gets the protocol and port for a profile and its group, see
+ /// .
+ ///
+ /// Profile to get the protocol and port for.
+ /// Group of the profile, null if not found.
+ /// Port profiles of the Ping Monitor.
+ /// True if the port profile can't be found.
+ /// Protocol (null if not overridden) and port input (null for ICMP or if not overridden).
+ public static (HostMonitorMethod? Method, string Port) GetMethodAndPort(ProfileInfo profile, GroupInfo group,
+ IEnumerable portProfiles, out bool portProfileNotFound)
+ {
+ portProfileNotFound = false;
+
+ HostMonitorMethod method;
+ int port;
+ string portInput;
+
+ if (profile.PingMonitor_OverrideMethod)
+ {
+ (method, port, portInput) =
+ (profile.PingMonitor_Method, profile.PingMonitor_Port, profile.PingMonitor_PortInput);
+ }
+ else if (group is { PingMonitor_OverrideMethod: true })
+ {
+ (method, port, portInput) = (group.PingMonitor_Method, group.PingMonitor_Port, group.PingMonitor_PortInput);
+ }
+ else
+ {
+ return (null, null);
+ }
+
+ return method != HostMonitorMethod.TCP
+ ? (method, null)
+ : (method, PingMonitorPortProfile.Decode(port, portInput, portProfiles, out portProfileNotFound));
+ }
+
+ ///
+ /// Gets the check of a profile for its tooltip in the Ping Monitor: "icmp", "22/tcp" or "HTTPS · 443/tcp" (port
+ /// profile), null if neither the profile nor its group overrides the protocol (the input is used).
+ ///
+ /// Profile.
+ /// Check of the profile, null if not overridden.
+ public static string GetCheckText(ProfileInfo profile)
+ {
+ return GetCheckText(profile, FindGroup(profile), SettingsManager.Current.PingMonitor_PortProfiles);
+ }
+
+ ///
+ /// Gets the check of a profile and its group, see .
+ ///
+ /// Profile.
+ /// Group of the profile, null if not found.
+ /// Port profiles of the Ping Monitor.
+ /// Check of the profile, null if not overridden.
+ public static string GetCheckText(ProfileInfo profile, GroupInfo group,
+ IEnumerable portProfiles)
+ {
+ var portProfileList = portProfiles as IList ?? [.. portProfiles];
+
+ var (method, port) = GetMethodAndPort(profile, group, portProfileList, out _);
+
+ if (method == null)
+ return null;
+
+ if (method != HostMonitorMethod.TCP)
+ return method.Value.ToString().ToLowerInvariant();
+
+ // TCP without a usable port (port profile not found, no saved port): the port has to be entered
+ if (string.IsNullOrWhiteSpace(port))
+ return "tcp";
+
+ // A port ("22" -> "22/tcp") or a port profile with its port ("HTTPS · 443/tcp")
+ if (PingMonitorPortProfile.TryParsePort(port, out var tcpPort))
+ return PingMonitorPortProfile.Format(tcpPort);
+
+ return PingMonitorPortProfile.TryResolvePort(port, portProfileList, out tcpPort)
+ ? $"{port} · {PingMonitorPortProfile.Format(tcpPort)}"
+ : port;
+ }
+
+ ///
+ /// Gets the group of a profile, null if it has none or it is not loaded (e.g. while the profile file is
+ /// switched) - throws in these cases.
+ ///
+ /// Profile.
+ /// Group of the profile, null if not found.
+ private static GroupInfo FindGroup(ProfileInfo profile)
+ {
+ return string.IsNullOrWhiteSpace(profile.Group)
+ ? null
+ : ProfileManager.LoadedProfileFileData?.Groups.FirstOrDefault(x => x.Name.Equals(profile.Group));
+ }
+}
diff --git a/Source/NETworkManager.Profiles/GroupInfo.cs b/Source/NETworkManager.Profiles/GroupInfo.cs
index d3a961b220..982fae332c 100644
--- a/Source/NETworkManager.Profiles/GroupInfo.cs
+++ b/Source/NETworkManager.Profiles/GroupInfo.cs
@@ -61,6 +61,12 @@ public GroupInfo(GroupInfo group) : this(group.Name)
PortScanner_Ports = group.PortScanner_Ports;
PortScanner_PortsInput = group.PortScanner_PortsInput;
+ // Ping Monitor
+ PingMonitor_OverrideMethod = group.PingMonitor_OverrideMethod;
+ PingMonitor_Method = group.PingMonitor_Method;
+ PingMonitor_Port = group.PingMonitor_Port;
+ PingMonitor_PortInput = group.PingMonitor_PortInput;
+
// DNS Lookup
DNSLookup_OverrideDNSServer = group.DNSLookup_OverrideDNSServer;
DNSLookup_DNSServer = group.DNSLookup_DNSServer;
@@ -234,6 +240,30 @@ public GroupInfo(GroupInfo group) : this(group.Name)
public bool PortScanner_OverridePorts { get; set; }
+ ///
+ /// Use the protocol () and the port () of the
+ /// group for its profiles (a profile can override them), otherwise the input of the Ping Monitor.
+ ///
+ public bool PingMonitor_OverrideMethod { get; set; }
+
+ ///
+ /// Protocol of the checks (ICMP or TCP).
+ ///
+ public HostMonitorMethod PingMonitor_Method { get; set; } = HostMonitorMethod.ICMP;
+
+ ///
+ /// Port of the TCP checks (one port, the Ping Monitor is not a port scanner). If a port profile was selected, its
+ /// port at the time the group was saved - used if the port profile of can't be
+ /// found (e.g. a profile file from another computer). 0 if none.
+ ///
+ public int PingMonitor_Port { get; set; }
+
+ ///
+ /// Port profile of the Ping Monitor, referenced by its ID (e.g. "{8f1c...}"), so it is also found after a rename.
+ /// Null if a port was entered.
+ ///
+ public string PingMonitor_PortInput { get; set; }
+
///
/// Ports to scan (ports and port ranges) for the profiles of the group, see
/// .
diff --git a/Source/NETworkManager.Profiles/GroupViewManager.cs b/Source/NETworkManager.Profiles/GroupViewManager.cs
index 7a796dbb4c..9e188fc3aa 100644
--- a/Source/NETworkManager.Profiles/GroupViewManager.cs
+++ b/Source/NETworkManager.Profiles/GroupViewManager.cs
@@ -15,6 +15,7 @@ public static class GroupViewManager
// Applications
new GroupViewInfo(GroupViewName.IPScanner, ApplicationManager.GetIcon(ApplicationName.IPScanner)),
new GroupViewInfo(GroupViewName.PortScanner, ApplicationManager.GetIcon(ApplicationName.PortScanner)),
+ new GroupViewInfo(GroupViewName.PingMonitor, ApplicationManager.GetIcon(ApplicationName.PingMonitor)),
new GroupViewInfo(GroupViewName.DNSLookup, ApplicationManager.GetIcon(ApplicationName.DNSLookup)),
new GroupViewInfo(GroupViewName.RemoteDesktop, ApplicationManager.GetIcon(ApplicationName.RemoteDesktop)),
new GroupViewInfo(GroupViewName.PowerShell, ApplicationManager.GetIcon(ApplicationName.PowerShell)),
diff --git a/Source/NETworkManager.Profiles/GroupViewName.cs b/Source/NETworkManager.Profiles/GroupViewName.cs
index 5f0de1cad6..a9efa5641c 100644
--- a/Source/NETworkManager.Profiles/GroupViewName.cs
+++ b/Source/NETworkManager.Profiles/GroupViewName.cs
@@ -5,6 +5,7 @@ public enum GroupViewName
General,
IPScanner,
PortScanner,
+ PingMonitor,
DNSLookup,
RemoteDesktop,
PowerShell,
diff --git a/Source/NETworkManager.Profiles/ProfileInfo.cs b/Source/NETworkManager.Profiles/ProfileInfo.cs
index eca7bbf3b3..66272d9ea7 100644
--- a/Source/NETworkManager.Profiles/ProfileInfo.cs
+++ b/Source/NETworkManager.Profiles/ProfileInfo.cs
@@ -87,6 +87,10 @@ public ProfileInfo(ProfileInfo profile)
PingMonitor_Enabled = profile.PingMonitor_Enabled;
PingMonitor_InheritHost = profile.PingMonitor_InheritHost;
PingMonitor_Host = profile.PingMonitor_Host;
+ PingMonitor_OverrideMethod = profile.PingMonitor_OverrideMethod;
+ PingMonitor_Method = profile.PingMonitor_Method;
+ PingMonitor_Port = profile.PingMonitor_Port;
+ PingMonitor_PortInput = profile.PingMonitor_PortInput;
// Traceroute
Traceroute_Enabled = profile.Traceroute_Enabled;
@@ -407,6 +411,29 @@ public ProfileInfo(ProfileInfo profile)
public bool PingMonitor_Enabled { get; set; }
public bool PingMonitor_InheritHost { get; set; } = true;
public string PingMonitor_Host { get; set; }
+ ///
+ /// Use the protocol () and the port () of the
+ /// profile instead of the ones of its group (or of the input of the Ping Monitor).
+ ///
+ public bool PingMonitor_OverrideMethod { get; set; }
+
+ ///
+ /// Protocol of the checks (ICMP or TCP).
+ ///
+ public HostMonitorMethod PingMonitor_Method { get; set; } = HostMonitorMethod.ICMP;
+
+ ///
+ /// Port of the TCP checks (one port, the Ping Monitor is not a port scanner). If a port profile was selected, its
+ /// port at the time the profile was saved - used if the port profile of can't be
+ /// found (e.g. a profile file from another computer). 0 if none.
+ ///
+ public int PingMonitor_Port { get; set; }
+
+ ///
+ /// Port profile of the Ping Monitor, referenced by its ID (e.g. "{8f1c...}"), so it is also found after a rename.
+ /// Null if a port was entered.
+ ///
+ public string PingMonitor_PortInput { get; set; }
public bool Traceroute_Enabled { get; set; }
public bool Traceroute_InheritHost { get; set; } = true;
diff --git a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs
index d4f583d229..93d174fdee 100644
--- a/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs
+++ b/Source/NETworkManager.Settings/GlobalStaticConfiguration.cs
@@ -310,7 +310,12 @@ public static class GlobalStaticConfiguration
public static bool PingMonitor_DontFragment => true;
public static int PingMonitor_Timeout => 4000; // ms
public static int PingMonitor_TTL => 64;
- public static int PingMonitor_WaitTime => 1000; // ms
+ public static NETworkManager.Models.Network.HostMonitorMethod PingMonitor_Method =>
+ NETworkManager.Models.Network.HostMonitorMethod.ICMP; // last used method is the default
+ public static string PingMonitor_Port => "443"; // port input of the TCP checks without history
+ public static int PingMonitor_TCPTimeout => 4000; // ms
+ public static int PingMonitor_WaitTime => 1000; // ms (ICMP)
+ public static int PingMonitor_TCPWaitTime => 1000; // ms (TCP)
public static bool PingMonitor_ExpandHostView => false;
public static int PingMonitor_ChartTime => 120; // s
public static int PingMonitor_HistoryHours => 12; // h (a workday)
diff --git a/Source/NETworkManager.Settings/SettingsInfo.cs b/Source/NETworkManager.Settings/SettingsInfo.cs
index 02803bb418..fc06a6a013 100644
--- a/Source/NETworkManager.Settings/SettingsInfo.cs
+++ b/Source/NETworkManager.Settings/SettingsInfo.cs
@@ -1993,6 +1993,23 @@ public ObservableCollection PortScanner_HostHistory
}
} = [];
+ ///
+ /// Ports the hosts of the host history were last scanned with (restored when a host is selected from the history).
+ ///
+ public ObservableCollection PortScanner_HostHistoryOptions
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ UpdateCollectionChanged(field, value);
+ field = value;
+ OnPropertyChanged();
+ }
+ } = [];
+
public ObservableCollection PortScanner_PortHistory
{
get;
@@ -2272,6 +2289,75 @@ public ObservableCollection PingMonitor_HostHistory
}
} = [];
+ ///
+ /// Protocol and port the hosts of the host history were last added with (restored when a host is selected from the history).
+ ///
+ public ObservableCollection PingMonitor_HostHistoryOptions
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ UpdateCollectionChanged(field, value);
+ field = value;
+ OnPropertyChanged();
+ }
+ } = [];
+
+ ///
+ /// Port profiles of the TCP checks of the Ping Monitor (one port each), see
+ /// .
+ ///
+ public ObservableCollection PingMonitor_PortProfiles
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ UpdateCollectionChanged(field, value);
+ field = value;
+ OnPropertyChanged();
+ }
+ } = [];
+
+ ///
+ /// Port input of the last TCP hosts (a port or a port profile), the default of the next input - also without a
+ /// history (a port profile is not added to the port history).
+ ///
+ public string PingMonitor_LastPort
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ field = value;
+ OnPropertyChanged();
+ }
+ } = GlobalStaticConfiguration.PingMonitor_Port;
+
+ ///
+ /// History of the port input of the TCP checks (ports and port profiles of the Ping Monitor).
+ ///
+ public ObservableCollection PingMonitor_PortHistory
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ UpdateCollectionChanged(field, value);
+ field = value;
+ OnPropertyChanged();
+ }
+ } = [];
+
public int PingMonitor_Buffer
{
get;
@@ -2324,6 +2410,45 @@ public int PingMonitor_TTL
}
} = GlobalStaticConfiguration.PingMonitor_TTL;
+ public NETworkManager.Models.Network.HostMonitorMethod PingMonitor_Method
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ field = value;
+ OnPropertyChanged();
+ }
+ } = GlobalStaticConfiguration.PingMonitor_Method;
+
+ public int PingMonitor_TCPTimeout
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ field = value;
+ OnPropertyChanged();
+ }
+ } = GlobalStaticConfiguration.PingMonitor_TCPTimeout;
+
+ public int PingMonitor_TCPWaitTime
+ {
+ get;
+ set
+ {
+ if (value == field)
+ return;
+
+ field = value;
+ OnPropertyChanged();
+ }
+ } = GlobalStaticConfiguration.PingMonitor_TCPWaitTime;
+
public int PingMonitor_WaitTime
{
get;
@@ -4992,11 +5117,15 @@ public SettingsInfo()
// Port Scanner
PortScanner_HostHistory.CollectionChanged += CollectionChanged;
+ PortScanner_HostHistoryOptions.CollectionChanged += CollectionChanged;
PortScanner_PortHistory.CollectionChanged += CollectionChanged;
PortScanner_PortProfiles.CollectionChanged += CollectionChanged;
// Ping Monitor
PingMonitor_HostHistory.CollectionChanged += CollectionChanged;
+ PingMonitor_HostHistoryOptions.CollectionChanged += CollectionChanged;
+ PingMonitor_PortHistory.CollectionChanged += CollectionChanged;
+ PingMonitor_PortProfiles.CollectionChanged += CollectionChanged;
// Traceroute
Traceroute_HostHistory.CollectionChanged += CollectionChanged;
diff --git a/Source/NETworkManager.Settings/SettingsManager.cs b/Source/NETworkManager.Settings/SettingsManager.cs
index 03114efb00..e33a8e364e 100644
--- a/Source/NETworkManager.Settings/SettingsManager.cs
+++ b/Source/NETworkManager.Settings/SettingsManager.cs
@@ -319,6 +319,11 @@ public static void Save()
// Create backup before modifying
CreateDailyBackupIfNeeded();
+ // Options of the host histories only for hosts that are still in the history (an entry can be removed from the
+ // history list, or the number of stored entries reduced, without a new start)
+ HostHistoryOptions.Prune(Current.PingMonitor_HostHistoryOptions, Current.PingMonitor_HostHistory);
+ HostHistoryOptions.Prune(Current.PortScanner_HostHistoryOptions, Current.PortScanner_HostHistory);
+
// Serialize to file
var filePath = GetSettingsFilePath();
@@ -968,6 +973,17 @@ private static void UpgradeToLatest(Version version)
Log.Info($"Add \"{profile.Name}\" to \"MDNSDiscovery_ServiceTypeProfiles\"...");
Current.MDNSDiscovery_ServiceTypeProfiles.Add(profile);
}
+
+ // Ping Monitor - Add the missing default port profiles (TCP checks). Added here and on the first start (not by the
+ // initializer of the setting), so their IDs are saved once and profiles / groups can refer to them. Like the
+ // mDNS block above: move it into the dated UpgradeTo_ of the release, otherwise deleted / renamed
+ // defaults come back with every update.
+ foreach (var portProfile in PingMonitorPortProfile.GetDefaultList().Where(portProfile =>
+ PingMonitorPortProfile.FindByName(Current.PingMonitor_PortProfiles, portProfile.Name) == null))
+ {
+ Log.Info($"Add \"{portProfile.Name}\" to \"PingMonitor_PortProfiles\"...");
+ Current.PingMonitor_PortProfiles.Add(portProfile);
+ }
}
#endregion
}
diff --git a/Source/NETworkManager.Tests/Export/ExportManagerToolTests.cs b/Source/NETworkManager.Tests/Export/ExportManagerToolTests.cs
index a36c755ba8..bcdf6c3b0a 100644
--- a/Source/NETworkManager.Tests/Export/ExportManagerToolTests.cs
+++ b/Source/NETworkManager.Tests/Export/ExportManagerToolTests.cs
@@ -80,6 +80,23 @@ public void PingMonitor_Consistent()
Assert.Equal(128, (int)files.JsonValue("TTL"));
}
+ [Fact]
+ public void PingMonitor_TCP_Columns()
+ {
+ // TCP: the port instead of TTL and bytes (no ICMP packet)
+ var files = ExportAll((f, t) => ExportManager.Export(f, t,
+ [
+ new PingInfo(Time, IPAddress, "host", 0, 3, IPStatus.Success) { Method = HostMonitorMethod.TCP, Port = 443 },
+ new PingInfo(Time, IPAddress, "host", IPStatus.DestinationPortUnreachable)
+ { Method = HostMonitorMethod.TCP, Port = 443 }
+ ], HostMonitorMethod.TCP));
+
+ AssertConsistent(files, "Timestamp,IPAddress,Hostname,Port,Status,Time");
+ Assert.Equal("443", files.CsvValue("Port"));
+ Assert.Equal(3, (long)files.JsonValue("Time"));
+ Assert.Equal("2026-11-08 10:15:30.123,10.0.0.1,\"host\",443,DestinationPortUnreachable,", files.CsvLines[2]);
+ }
+
[Fact]
public void PingMonitor_NoReply_Empty()
{
diff --git a/Source/NETworkManager.Tests/Network/HostMonitorTests.cs b/Source/NETworkManager.Tests/Network/HostMonitorTests.cs
new file mode 100644
index 0000000000..ef68b667f0
--- /dev/null
+++ b/Source/NETworkManager.Tests/Network/HostMonitorTests.cs
@@ -0,0 +1,124 @@
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Net.NetworkInformation;
+using System.Threading;
+using System.Threading.Tasks;
+using NETworkManager.Models.Network;
+using Xunit;
+
+namespace NETworkManager.Tests.Network;
+
+public class HostMonitorTests
+{
+ private static readonly IPAddress Address = IPAddress.Parse("10.0.0.1");
+
+ ///
+ /// Probe that runs the given steps one after another, then waits until it is canceled.
+ ///
+ private sealed class FakeProbe(params Func>[] steps) : IHostMonitorProbe
+ {
+ private int _calls;
+
+ public string Name => "Fake";
+
+ public Task ProbeAsync(CancellationToken cancellationToken)
+ {
+ var call = _calls++;
+
+ return call < steps.Length ? steps[call](cancellationToken) : WaitUntilCanceled(cancellationToken);
+ }
+
+ private static async Task WaitUntilCanceled(CancellationToken cancellationToken)
+ {
+ await Task.Delay(Timeout.Infinite, cancellationToken);
+
+ return null;
+ }
+ }
+
+ private static Task Success(CancellationToken _)
+ {
+ // Another IP address instance: the monitor sets its own
+ return Task.FromResult(new PingInfo(DateTime.Now, IPAddress.Parse("10.0.0.1"), 0, 5, IPStatus.Success));
+ }
+
+ [Fact]
+ public async Task FailedCheckIsReportedAndTheMonitorKeepsChecking()
+ {
+ var probe = new FakeProbe(_ => throw new InvalidOperationException("No network"), Success);
+ var monitor = new HostMonitor(Address, "server", probe) { WaitTime = 1 };
+
+ using var cts = new CancellationTokenSource();
+ var received = new List();
+ var stopped = 0;
+ var hostnameResolved = false;
+
+ monitor.PingReceived += (_, e) =>
+ {
+ received.Add(e);
+
+ if (received.Count == 2)
+ cts.Cancel();
+ };
+ monitor.Stopped += (_, _) => stopped++;
+ monitor.HostnameResolved += (_, _) => hostnameResolved = true;
+
+ await monitor.RunAsync(cts.Token).WaitAsync(TimeSpan.FromSeconds(10));
+
+ Assert.Equal(2, received.Count);
+
+ Assert.Equal(IPStatus.Unknown, received[0].Args.Status);
+ Assert.Equal("No network", received[0].ErrorMessage);
+
+ Assert.Equal(IPStatus.Success, received[1].Args.Status);
+ Assert.Null(received[1].ErrorMessage);
+
+ // IP address and hostname of the monitor (a known hostname: no PTR lookup)
+ Assert.All(received, x => Assert.Same(Address, x.Args.IPAddress));
+ Assert.All(received, x => Assert.Equal("server", x.Args.Hostname));
+ Assert.False(hostnameResolved);
+
+ Assert.Equal(1, stopped);
+ Assert.Null(monitor.StopErrorMessage);
+ }
+
+ [Fact]
+ public async Task CancelWhileCheckingStopsOnce()
+ {
+ var monitor = new HostMonitor(Address, "server", new FakeProbe()) { WaitTime = 1 };
+
+ using var cts = new CancellationTokenSource();
+ var received = 0;
+ var stopped = 0;
+
+ monitor.PingReceived += (_, _) => received++;
+ monitor.Stopped += (_, _) => stopped++;
+
+ var run = monitor.RunAsync(cts.Token);
+
+ await Task.Delay(50);
+ await cts.CancelAsync();
+ await run.WaitAsync(TimeSpan.FromSeconds(10));
+
+ Assert.Equal(0, received);
+ Assert.Equal(1, stopped);
+ Assert.Null(monitor.StopErrorMessage);
+ }
+
+ [Fact]
+ public async Task CanceledBeforeTheStartStopsOnce()
+ {
+ var monitor = new HostMonitor(Address, "server", new FakeProbe(Success)) { WaitTime = 1 };
+
+ using var cts = new CancellationTokenSource();
+ await cts.CancelAsync();
+
+ var stopped = 0;
+ monitor.Stopped += (_, _) => stopped++;
+
+ await monitor.RunAsync(cts.Token).WaitAsync(TimeSpan.FromSeconds(10));
+
+ Assert.Equal(1, stopped);
+ }
+}
diff --git a/Source/NETworkManager.Tests/Network/PingMonitorHostHelperTests.cs b/Source/NETworkManager.Tests/Network/PingMonitorHostHelperTests.cs
index 06b1eb3462..3c6b30966b 100644
--- a/Source/NETworkManager.Tests/Network/PingMonitorHostHelperTests.cs
+++ b/Source/NETworkManager.Tests/Network/PingMonitorHostHelperTests.cs
@@ -40,6 +40,25 @@ public void IPv6IsComparedByValue()
Assert.Single(alreadyMonitored);
}
+ [Fact]
+ public void PortIsPartOfTheKey()
+ {
+ // TCP 443 is monitored, TCP 22 for the same IP address is added
+ var (hostsToAdd, alreadyMonitored) =
+ PingMonitorHostHelper.SplitAlreadyMonitored([(A, "server")], [22, 443], [(IPAddress.Parse("10.0.0.1"), 443)]);
+
+ Assert.Equal([((A, "server"), 22)], hostsToAdd);
+ Assert.Equal([((A, "server"), 443)], alreadyMonitored);
+ }
+
+ [Fact]
+ public void EveryHostWithEveryPortInTheOrderOfTheInput()
+ {
+ var (hostsToAdd, _) = PingMonitorHostHelper.SplitAlreadyMonitored([(A, null), (B, null)], [80, 443], []);
+
+ Assert.Equal([(A, 80), (A, 443), (B, 80), (B, 443)], hostsToAdd.Select(x => (x.host.ipAddress, x.port)));
+ }
+
[Fact]
public void EntriesOfTheInputForTheSameIPAddressAreKept()
{
diff --git a/Source/NETworkManager.Tests/Network/PingMonitorPortProfileTests.cs b/Source/NETworkManager.Tests/Network/PingMonitorPortProfileTests.cs
new file mode 100644
index 0000000000..17e889add0
--- /dev/null
+++ b/Source/NETworkManager.Tests/Network/PingMonitorPortProfileTests.cs
@@ -0,0 +1,150 @@
+using System.Linq;
+using NETworkManager.Models.Network;
+using Xunit;
+
+namespace NETworkManager.Tests.Network;
+
+///
+/// Port of the TCP checks of the Ping Monitor: one port ("443" or "443/tcp") or the name of a port profile.
+///
+public class PingMonitorPortProfileTests
+{
+ private static readonly PingMonitorPortProfileInfo Https = new("HTTPS", 443);
+ private static readonly PingMonitorPortProfileInfo Ssh = new("SSH", 22);
+
+ [Theory]
+ [InlineData("443", 443)]
+ [InlineData("443/tcp", 443)]
+ [InlineData(" 22/TCP ", 22)]
+ [InlineData("443 /tcp", 443)]
+ [InlineData("65535", 65535)]
+ public void TryParsePort_Valid(string text, int expected)
+ {
+ Assert.True(PingMonitorPortProfile.TryParsePort(text, out var port));
+ Assert.Equal(expected, port);
+ }
+
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ [InlineData("0")]
+ [InlineData("65536")]
+ [InlineData("443/udp")]
+ [InlineData("22; 443")]
+ [InlineData("1-1024")]
+ [InlineData("HTTPS")]
+ public void TryParsePort_Invalid(string text)
+ {
+ Assert.False(PingMonitorPortProfile.TryParsePort(text, out _));
+ }
+
+ [Fact]
+ public void Format_PortWithProtocol()
+ {
+ Assert.Equal("443/tcp", PingMonitorPortProfile.Format(443));
+ }
+
+ [Theory]
+ [InlineData("HTTPS", true)]
+ [InlineData("WinRM (HTTPS)", true)]
+ [InlineData("443", false)]
+ [InlineData("443/tcp", false)]
+ [InlineData(" ", false)]
+ public void IsValidName(string name, bool expected)
+ {
+ // A name is entered instead of a port, so it must not be one
+ Assert.Equal(expected, PingMonitorPortProfile.IsValidName(name));
+ }
+
+ [Theory]
+ [InlineData("443", 443)]
+ [InlineData("3389/tcp", 3389)]
+ [InlineData("https", 443)]
+ [InlineData(" SSH ", 22)]
+ public void TryResolvePort_PortOrName(string input, int expected)
+ {
+ Assert.True(PingMonitorPortProfile.TryResolvePort(input, [Https, Ssh], out var port));
+ Assert.Equal(expected, port);
+ }
+
+ [Theory]
+ [InlineData("Webserver")]
+ [InlineData("80; 443")]
+ [InlineData("")]
+ public void TryResolvePort_Invalid(string input)
+ {
+ Assert.False(PingMonitorPortProfile.TryResolvePort(input, [Https, Ssh], out _));
+ }
+
+ [Fact]
+ public void TryResolvePort_PortProfileWithInvalidPort()
+ {
+ // E.g. a hand-edited settings file: the port profile is no valid input (a TCP probe needs 1 - 65535)
+ Assert.False(PingMonitorPortProfile.TryResolvePort("broken", [new PingMonitorPortProfileInfo("broken", 0)], out _));
+ Assert.False(PingMonitorPortProfile.TryResolvePort("big", [new PingMonitorPortProfileInfo("big", 70000)], out _));
+ }
+
+ [Theory]
+ [InlineData("+80")]
+ [InlineData("-1")]
+ [InlineData("8 0")]
+ public void TryParsePort_RejectsSignsAndSpacesInTheNumber(string text)
+ {
+ // The dialog validates and reads the port with this parser
+ Assert.False(PingMonitorPortProfile.TryParsePort(text, out _));
+ }
+
+ [Fact]
+ public void Encode_PortProfileIsReferencedByItsId()
+ {
+ var (port, portInput) = PingMonitorPortProfile.Encode("https", [Https]);
+
+ Assert.Equal(443, port);
+ Assert.Equal(Https.Id.ToString("B"), portInput);
+ }
+
+ [Fact]
+ public void Encode_PortHasNoReference()
+ {
+ Assert.Equal((8443, null), PingMonitorPortProfile.Encode("8443/tcp", [Https]));
+ }
+
+ [Fact]
+ public void Decode_CurrentNameOrSavedPort()
+ {
+ var (port, portInput) = PingMonitorPortProfile.Encode("HTTPS", [Https]);
+ var renamed = new PingMonitorPortProfileInfo { Id = Https.Id, Name = "Web (TLS)", Port = 443 };
+
+ Assert.Equal("Web (TLS)", PingMonitorPortProfile.Decode(port, portInput, [renamed], out var notFound));
+ Assert.False(notFound);
+
+ Assert.Equal("443", PingMonitorPortProfile.Decode(port, portInput, [], out notFound));
+ Assert.True(notFound);
+
+ Assert.Null(PingMonitorPortProfile.Decode(0, null, [], out _));
+ }
+
+ [Theory]
+ [InlineData(null, "icmp")]
+ [InlineData("", "icmp")]
+ [InlineData("443", "tcp")]
+ [InlineData("443/tcp", "tcp")]
+ [InlineData("https", "tcp (443/tcp)")]
+ [InlineData("unknown", "tcp")]
+ public void GetProtocolText(string portInput, string expected)
+ {
+ // Run command: the protocol below the input (ping 1.1.1.1 -> icmp, ping 1.1.1.1 443 -> tcp)
+ Assert.Equal(expected, PingMonitorPortProfile.GetProtocolText(portInput, [Https]));
+ }
+
+ [Fact]
+ public void DefaultList_UniqueValidNamesAndPorts()
+ {
+ var list = PingMonitorPortProfile.GetDefaultList();
+
+ Assert.All(list, x => Assert.True(PingMonitorPortProfile.IsValidName(x.Name)));
+ Assert.Equal(list.Count, list.Select(x => x.Name.ToLowerInvariant()).Distinct().Count());
+ Assert.Equal(list.Count, list.Select(x => x.Port).Distinct().Count());
+ Assert.Contains(list, x => x is { Name: "HTTPS", Port: 443 });
+ }
+}
diff --git a/Source/NETworkManager.Tests/Network/TCPHostMonitorProbeTests.cs b/Source/NETworkManager.Tests/Network/TCPHostMonitorProbeTests.cs
new file mode 100644
index 0000000000..aa58ac736f
--- /dev/null
+++ b/Source/NETworkManager.Tests/Network/TCPHostMonitorProbeTests.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Net;
+using System.Net.NetworkInformation;
+using System.Net.Sockets;
+using System.Threading;
+using System.Threading.Tasks;
+using NETworkManager.Models.Network;
+using Xunit;
+
+namespace NETworkManager.Tests.Network;
+
+public class TCPHostMonitorProbeTests
+{
+ [Fact]
+ public void Name_IsTCP()
+ {
+ var probe = new TCPHostMonitorProbe(IPAddress.Loopback, 443, 1000);
+
+ Assert.Equal("TCP", probe.Name);
+ }
+
+ [Fact]
+ public void Constructor_InvalidPort_Throws()
+ {
+ Assert.Throws(() => new TCPHostMonitorProbe(IPAddress.Loopback, 0, 1000));
+ Assert.Throws(() => new TCPHostMonitorProbe(IPAddress.Loopback, 65536, 1000));
+ }
+
+ [Fact]
+ public async Task ProbeAsync_OpenPort_ReturnsSuccess()
+ {
+ var listener = new TcpListener(IPAddress.Loopback, 0);
+ listener.Start();
+
+ try
+ {
+ var port = ((IPEndPoint)listener.LocalEndpoint).Port;
+
+ var info = await new TCPHostMonitorProbe(IPAddress.Loopback, port, 2000).ProbeAsync(CancellationToken.None);
+
+ Assert.Equal(IPStatus.Success, info.Status);
+ Assert.Equal(HostMonitorMethod.TCP, info.Method);
+ Assert.Equal(port, info.Port);
+ Assert.True(info.Time >= 0);
+ Assert.Equal(IPAddress.Loopback, info.IPAddress);
+ }
+ finally
+ {
+ listener.Stop();
+ }
+ }
+
+ [Fact]
+ public async Task ProbeAsync_ClosedPort_ReturnsDestinationPortUnreachable()
+ {
+ // Get a port that was free a moment ago: nothing listens on it anymore
+ var listener = new TcpListener(IPAddress.Loopback, 0);
+ listener.Start();
+ var port = ((IPEndPoint)listener.LocalEndpoint).Port;
+ listener.Stop();
+
+ var info = await new TCPHostMonitorProbe(IPAddress.Loopback, port, 2000).ProbeAsync(CancellationToken.None);
+
+ Assert.Equal(IPStatus.DestinationPortUnreachable, info.Status);
+ Assert.Equal(0, info.Time);
+ Assert.Equal(port, info.Port);
+ }
+
+ [Fact]
+ public async Task ProbeAsync_CanceledToken_ThrowsOperationCanceledException()
+ {
+ var probe = new TCPHostMonitorProbe(IPAddress.Loopback, 443, 2000);
+
+ using var cts = new CancellationTokenSource();
+ await cts.CancelAsync();
+
+ await Assert.ThrowsAnyAsync(() => probe.ProbeAsync(cts.Token));
+ }
+}
diff --git a/Source/NETworkManager.Tests/Profiles/PingMonitorProfileTests.cs b/Source/NETworkManager.Tests/Profiles/PingMonitorProfileTests.cs
new file mode 100644
index 0000000000..6aabf5b9fc
--- /dev/null
+++ b/Source/NETworkManager.Tests/Profiles/PingMonitorProfileTests.cs
@@ -0,0 +1,110 @@
+using NETworkManager.Models.Network;
+using NETworkManager.Profiles;
+using Xunit;
+using PingMonitorProfile = NETworkManager.Profiles.Application.PingMonitor;
+
+namespace NETworkManager.Tests.Profiles;
+
+///
+/// Protocol and port of a profile in the Ping Monitor: profile, then group, otherwise the input; port profiles of
+/// the Ping Monitor referenced by their ID like the ports of the Port Scanner.
+///
+public class PingMonitorProfileTests
+{
+ private static readonly PingMonitorPortProfileInfo Https = new("HTTPS", 443);
+
+ [Fact]
+ public void NoOverrideKeepsTheInput()
+ {
+ var result = PingMonitorProfile.GetMethodAndPort(new ProfileInfo(), new GroupInfo("Group"), [Https],
+ out var notFound);
+
+ Assert.Equal((null, null), result);
+ Assert.False(notFound);
+ }
+
+ [Fact]
+ public void ProfileWithoutGroupKeepsTheInput()
+ {
+ Assert.Equal((null, null), PingMonitorProfile.GetMethodAndPort(new ProfileInfo(), null, [Https], out _));
+ }
+
+ [Fact]
+ public void GroupOverride()
+ {
+ var group = new GroupInfo("Group")
+ { PingMonitor_OverrideMethod = true, PingMonitor_Method = HostMonitorMethod.TCP, PingMonitor_Port = 22 };
+
+ Assert.Equal((HostMonitorMethod.TCP, "22"),
+ PingMonitorProfile.GetMethodAndPort(new ProfileInfo(), group, [Https], out _));
+ }
+
+ [Fact]
+ public void ProfileOverridesTheGroup()
+ {
+ var profile = new ProfileInfo { PingMonitor_OverrideMethod = true, PingMonitor_Method = HostMonitorMethod.ICMP };
+ var group = new GroupInfo("Group")
+ { PingMonitor_OverrideMethod = true, PingMonitor_Method = HostMonitorMethod.TCP, PingMonitor_Port = 22 };
+
+ // ICMP has no port
+ Assert.Equal((HostMonitorMethod.ICMP, null),
+ PingMonitorProfile.GetMethodAndPort(profile, group, [Https], out _));
+ }
+
+ [Fact]
+ public void PortProfileIsFoundAfterARename()
+ {
+ var profile = CreateTcpProfile("HTTPS");
+ var renamed = new PingMonitorPortProfileInfo { Id = Https.Id, Name = "Web (TLS)", Port = 443 };
+
+ var (_, port) = PingMonitorProfile.GetMethodAndPort(profile, null, [renamed], out var notFound);
+
+ Assert.Equal("Web (TLS)", port);
+ Assert.False(notFound);
+ }
+
+ [Fact]
+ public void PortProfileNotFoundUsesTheSavedPort()
+ {
+ // E.g. a profile file from another computer: the port profiles are saved in the settings
+ var profile = CreateTcpProfile("HTTPS");
+
+ var (method, port) = PingMonitorProfile.GetMethodAndPort(profile, null, [], out var notFound);
+
+ Assert.Equal(HostMonitorMethod.TCP, method);
+ Assert.Equal("443", port);
+ Assert.True(notFound);
+ }
+
+ [Fact]
+ public void CheckText()
+ {
+ var group = new GroupInfo("Group")
+ { PingMonitor_OverrideMethod = true, PingMonitor_Method = HostMonitorMethod.TCP, PingMonitor_Port = 22 };
+ var icmp = new ProfileInfo { PingMonitor_OverrideMethod = true, PingMonitor_Method = HostMonitorMethod.ICMP };
+
+ Assert.Null(PingMonitorProfile.GetCheckText(new ProfileInfo(), null, [Https]));
+ Assert.Equal("22/tcp", PingMonitorProfile.GetCheckText(new ProfileInfo(), group, [Https]));
+ Assert.Equal("icmp", PingMonitorProfile.GetCheckText(icmp, group, [Https]));
+ Assert.Equal("HTTPS · 443/tcp", PingMonitorProfile.GetCheckText(CreateTcpProfile("HTTPS"), group, [Https]));
+
+ // TCP whose port profile is missing and without a saved port: still shown as TCP
+ var noPort = new ProfileInfo
+ {
+ PingMonitor_OverrideMethod = true, PingMonitor_Method = HostMonitorMethod.TCP, PingMonitor_Port = 0,
+ PingMonitor_PortInput = System.Guid.NewGuid().ToString("B")
+ };
+ Assert.Equal("tcp", PingMonitorProfile.GetCheckText(noPort, null, [Https]));
+ }
+
+ private static ProfileInfo CreateTcpProfile(string portInput)
+ {
+ var (port, input) = PingMonitorPortProfile.Encode(portInput, [Https]);
+
+ return new ProfileInfo
+ {
+ PingMonitor_OverrideMethod = true, PingMonitor_Method = HostMonitorMethod.TCP, PingMonitor_Port = port,
+ PingMonitor_PortInput = input
+ };
+ }
+}
diff --git a/Source/NETworkManager.Tests/RunCommand/RunCommandParserTests.cs b/Source/NETworkManager.Tests/RunCommand/RunCommandParserTests.cs
index d5abed0059..046a8d233a 100644
--- a/Source/NETworkManager.Tests/RunCommand/RunCommandParserTests.cs
+++ b/Source/NETworkManager.Tests/RunCommand/RunCommandParserTests.cs
@@ -11,7 +11,13 @@ public class RunCommandParserTests
new()
{
Type = RunCommandType.Application, Application = ApplicationName.PingMonitor, Command = "pingmonitor",
- Aliases = ["ping"], SupportsTarget = true, SupportsProfile = true
+ Aliases = ["ping"], SupportsTarget = true, SupportsProfile = true, Argument = RunCommandArgument.Port,
+ SyntaxParts =
+ [
+ RunCommandSyntaxPart.Required(RunCommandSyntaxPartKind.Target, "Hosts"),
+ RunCommandSyntaxPart.Optional(RunCommandSyntaxPartKind.Argument, "Port | Port profile"),
+ RunCommandSyntaxPart.Profile("Profile")
+ ]
},
new()
{
@@ -321,7 +327,23 @@ public void TargetThatLooksLikeAType()
}
[Theory]
- [InlineData("ping 10.0.0.1 foo", "foo")]
+ [InlineData("ping 10.0.0.1", "10.0.0.1", null)]
+ [InlineData("ping 10.0.0.1 443", "10.0.0.1", "443")]
+ [InlineData("ping 10.0.0.1 443/tcp", "10.0.0.1", "443/tcp")]
+ [InlineData("ping 10.0.0.1; 10.0.0.2 https", "10.0.0.1;10.0.0.2", "https")]
+ [InlineData("ping 10.0.0.1 \"WinRM (HTTPS)\"", "10.0.0.1", "WinRM (HTTPS)")]
+ public void PingWithPort(string input, string target, string port)
+ {
+ // Ping Monitor: a port or port profile after the hosts (TCP); optional (ICMP)
+ var result = Parse(input);
+
+ Assert.Equal(RunCommandParseError.None, result.Error);
+ Assert.Equal(target, result.Target);
+ Assert.Equal(port, result.Argument);
+ }
+
+ [Theory]
+ [InlineData("rdp 10.0.0.1 foo", "foo")]
[InlineData("dns borntoberoot.net 1.1.1.1 8.8.8.8", "8.8.8.8")]
[InlineData("dns borntoberoot.net a aaaa 1.1.1.1", "aaaa")]
public void UnknownArgument(string input, string unknown)
diff --git a/Source/NETworkManager.Tests/Utilities/HostHistoryOptionsTests.cs b/Source/NETworkManager.Tests/Utilities/HostHistoryOptionsTests.cs
new file mode 100644
index 0000000000..c23a4ccbce
--- /dev/null
+++ b/Source/NETworkManager.Tests/Utilities/HostHistoryOptionsTests.cs
@@ -0,0 +1,61 @@
+using System.Collections.ObjectModel;
+using System.Linq;
+using NETworkManager.Models.Network;
+using NETworkManager.Utilities;
+using Xunit;
+
+namespace NETworkManager.Tests.Utilities;
+
+///
+/// Options of the hosts of a history (e.g. protocol and port of the Ping Monitor): the newest first, only hosts that
+/// are still in the history.
+///
+public class HostHistoryOptionsTests
+{
+ [Fact]
+ public void SetAddsTheNewestFirstAndReplacesTheHost()
+ {
+ ObservableCollection entries = [];
+ ObservableCollection history = ["server-02", "server-01"];
+
+ HostHistoryOptions.Set(entries, history, new PingMonitorHostHistoryInfo("server-01", HostMonitorMethod.ICMP, null));
+ HostHistoryOptions.Set(entries, history, new PingMonitorHostHistoryInfo("server-02", HostMonitorMethod.TCP, "22"));
+ HostHistoryOptions.Set(entries, history, new PingMonitorHostHistoryInfo("server-01", HostMonitorMethod.TCP, "HTTPS"));
+
+ Assert.Equal(["server-01", "server-02"], entries.Select(x => x.Host));
+ Assert.Equal("HTTPS", HostHistoryOptions.Find(entries, "server-01").Port);
+ }
+
+ [Fact]
+ public void HostsThatLeftTheHistoryAreRemoved()
+ {
+ ObservableCollection entries =
+ [new("old", "1-1024"), new("10.0.0.1", "22"), new("removed", "80")];
+
+ // "old" dropped out of the history, "removed" was removed from the list
+ HostHistoryOptions.Prune(entries, ["10.0.0.1"]);
+
+ Assert.Equal(["10.0.0.1"], entries.Select(x => x.Host));
+ }
+
+ [Fact]
+ public void NoHistoryKeepsNoOptions()
+ {
+ ObservableCollection entries = [];
+
+ // "Number of stored entries" is 0: the history stays empty
+ HostHistoryOptions.Set(entries, [], new PortScannerHostHistoryInfo("10.0.0.1", "22"));
+
+ Assert.Empty(entries);
+ }
+
+ [Fact]
+ public void FindIsExactLikeTheHistory()
+ {
+ ObservableCollection entries = [new("Server-01", "22")];
+
+ Assert.NotNull(HostHistoryOptions.Find(entries, "Server-01"));
+ Assert.Null(HostHistoryOptions.Find(entries, "server-01"));
+ Assert.Null(HostHistoryOptions.Find(entries, null));
+ }
+}
diff --git a/Source/NETworkManager.Utilities.WPF/ComboBoxPickHelper.cs b/Source/NETworkManager.Utilities.WPF/ComboBoxPickHelper.cs
new file mode 100644
index 0000000000..f536895624
--- /dev/null
+++ b/Source/NETworkManager.Utilities.WPF/ComboBoxPickHelper.cs
@@ -0,0 +1,71 @@
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Input;
+
+namespace NETworkManager.Utilities.WPF;
+
+///
+/// Reports an entry that is picked from the drop-down list of a : a click on an entry, or Enter
+/// on an entry that was highlighted with the arrow keys while the list is open. Not when typed text matches an entry - an editable ComboBox
+/// selects that entry while typing (e.g. a host of the history that gets its options, see HostHistoryOptions).
+///
+public static class ComboBoxPickHelper
+{
+ ///
+ /// Calls with the selected item when an entry was picked from the list.
+ ///
+ /// ComboBox with a drop-down list (e.g. a history).
+ /// Action that gets the picked item.
+ public static void OnItemPicked(ComboBox comboBox, Action