diff --git a/Source/NETworkManager.Models/Network/IPScanner.cs b/Source/NETworkManager.Models/Network/IPScanner.cs index a7bf5a6145..3cde907425 100644 --- a/Source/NETworkManager.Models/Network/IPScanner.cs +++ b/Source/NETworkManager.Models/Network/IPScanner.cs @@ -93,7 +93,7 @@ public void ScanAsync(IEnumerable<(IPAddress ipAddress, string hostname)> hosts, // Start netbios lookup async (if enabled) var netbiosTask = options.NetBIOSEnabled ? NetBIOSResolver.ResolveAsync(host.ipAddress, options.NetBIOSTimeout, cancellationToken) - : Task.FromResult(new NetBIOSInfo()); + : Task.FromResult(new NetBIOSInfo(host.ipAddress)); // Get ping result pingTask.Wait(cancellationToken); @@ -214,26 +214,34 @@ private Task PingAsync(IPAddress ipAddress, CancellationToken cancella for (var i = 0; i < options.ICMPAttempts; i++) { + // Get timestamp + var timestamp = DateTime.Now; + try { - // Get timestamp - var timestamp = DateTime.Now; - var pingReply = ping.Send(ipAddress, options.ICMPTimeout, options.ICMPBuffer); // Success if (pingReply is { Status: IPStatus.Success }) { - // IPv4 - if (ipAddress.AddressFamily == AddressFamily.InterNetwork) - return new PingInfo(timestamp, pingReply.Address, pingReply.Buffer.Length, - pingReply.RoundtripTime, - pingReply.Options!.Ttl, pingReply.Status); - - // IPv6 - return new PingInfo(timestamp, pingReply.Address, pingReply.Buffer.Length, - pingReply.RoundtripTime, - pingReply.Status); + switch (ipAddress.AddressFamily) + { + case AddressFamily.InterNetwork: + return new PingInfo( + timestamp, + pingReply.Address, + pingReply.Buffer.Length, + pingReply.RoundtripTime, + pingReply.Options!.Ttl, + pingReply.Status); + case AddressFamily.InterNetworkV6: + return new PingInfo( + timestamp, + pingReply.Address, + pingReply.Buffer.Length, + pingReply.RoundtripTime, + pingReply.Status); + } } // Failed @@ -242,6 +250,8 @@ private Task PingAsync(IPAddress ipAddress, CancellationToken cancella } catch (PingException) { + // Ping failed with unknown status + return new PingInfo(timestamp, ipAddress, IPStatus.Unknown); } // Don't scan again, if the user has canceled (when more than 1 attempt) @@ -249,7 +259,8 @@ private Task PingAsync(IPAddress ipAddress, CancellationToken cancella break; } - return new PingInfo(); + // Fall back to unknown status + return new PingInfo(DateTime.Now, ipAddress, IPStatus.Unknown); }, cancellationToken); } diff --git a/Source/NETworkManager.Models/Network/NetBIOSInfo.cs b/Source/NETworkManager.Models/Network/NetBIOSInfo.cs index 1f7111baef..2e97f3338d 100644 --- a/Source/NETworkManager.Models/Network/NetBIOSInfo.cs +++ b/Source/NETworkManager.Models/Network/NetBIOSInfo.cs @@ -10,9 +10,10 @@ public class NetBIOSInfo /// /// Constructor for an unreachable host. /// - public NetBIOSInfo() + public NetBIOSInfo(IPAddress ipAddress) { IsReachable = false; + IPAddress = ipAddress; } /// @@ -20,7 +21,7 @@ public NetBIOSInfo() /// /// IP address of the host. /// Computer name of the host. - /// User name of the host. + /// Username of the host. /// Group name or domain of the host. /// MAC address of the host. /// Vendor of the host based on the MAC address. @@ -52,7 +53,7 @@ public NetBIOSInfo(IPAddress ipAddress, string computerName, string userName, st public string ComputerName { get; set; } /// - /// User name of the host. + /// Username of the host. /// public string UserName { get; set; } diff --git a/Source/NETworkManager.Models/Network/NetBIOSResolver.cs b/Source/NETworkManager.Models/Network/NetBIOSResolver.cs index 13ced63ef5..342de111fe 100644 --- a/Source/NETworkManager.Models/Network/NetBIOSResolver.cs +++ b/Source/NETworkManager.Models/Network/NetBIOSResolver.cs @@ -59,17 +59,17 @@ public static async Task ResolveAsync(IPAddress ipAddress, int time var receiveTask = udpClient.ReceiveAsync(); if (!receiveTask.Wait(timeout, cancellationToken)) - return new NetBIOSInfo(); + return new NetBIOSInfo(ipAddress); var response = receiveTask.Result; if (response.Buffer.Length < ResponseBaseLen || response.Buffer[ResponseTypePos] != ResponseTypeNbstat) - return new NetBIOSInfo(); // response was too short + return new NetBIOSInfo(ipAddress); // response was too short var count = response.Buffer[ResponseBaseLen - 1] & 0xFF; if (response.Buffer.Length < ResponseBaseLen + ResponseBlockLen * count) - return new NetBIOSInfo(); // data was truncated or something is wrong + return new NetBIOSInfo(ipAddress); // data was truncated or something is wrong var result = ExtractNames(response.Buffer, count); @@ -96,7 +96,7 @@ public static async Task ResolveAsync(IPAddress ipAddress, int time } catch (Exception) { - return null; + return new NetBIOSInfo(ipAddress); } finally { diff --git a/Source/NETworkManager/Views/IPScannerView.xaml b/Source/NETworkManager/Views/IPScannerView.xaml index 390262aea9..c7a9051a78 100644 --- a/Source/NETworkManager/Views/IPScannerView.xaml +++ b/Source/NETworkManager/Views/IPScannerView.xaml @@ -632,7 +632,7 @@ - + @@ -645,7 +645,7 @@ - + @@ -664,7 +664,7 @@ - + @@ -677,7 +677,7 @@ - + @@ -817,7 +817,7 @@ - + @@ -830,7 +830,7 @@ - + @@ -843,7 +843,7 @@ - + @@ -856,7 +856,7 @@ - + @@ -869,7 +869,7 @@ - + @@ -929,7 +929,7 @@ - + @@ -977,7 +977,7 @@ - + @@ -990,7 +990,7 @@ - + diff --git a/Website/docs/changelog/next-release.md b/Website/docs/changelog/next-release.md index 2539a84c51..771ba31bd8 100644 --- a/Website/docs/changelog/next-release.md +++ b/Website/docs/changelog/next-release.md @@ -22,6 +22,7 @@ Release date: **xx.xx.2024** ## What's new? - **WiFi** + - 6 GHz networks are not supported. [#2912](https://github.com/BornToBeRoot/NETworkManager/pull/2912) [#2928](https://github.com/BornToBeRoot/NETworkManager/pull/2928) - `WPA3 Personal (SAE)`, `WPA3 Enterprise` and `WPA3 Enterprise (192-bit)` are now supported. [#2912](https://github.com/BornToBeRoot/NETworkManager/pull/2912) - `802.11be` (`EHT`) is now supported. [#2912](https://github.com/BornToBeRoot/NETworkManager/pull/2912) @@ -39,11 +40,16 @@ Release date: **xx.xx.2024** - Changed the Welcome dialog from `MahApps.Metro.Controls.Dialogs` to `MahApps.Metro.SimpleChildWindow`, so the main window can be dragged and resized on the first start. [#2914](https://github.com/BornToBeRoot/NETworkManager/pull/2914) - **WiFi** + - Fixed a bug that caused the scan process to crash when a 6 GHz network was found. [#2912](https://github.com/BornToBeRoot/NETworkManager/pull/2912) +- **IP Scanner** + + - Fixed two `NullReferenceException` in ICMP & NETBIOS for some IP addresses. [#2964](https://github.com/BornToBeRoot/NETworkManager/pull/2964) + ## Dependencies, Refactoring & Documentation -Migrated code for some loading indicators from the library [LoadingIndicators.WPF] (https://github.com/zeluisping/LoadingIndicators.WPF) to the NETworkManager repo, as the original repo looks unmaintained and has problems with MahApps.Metro version 2 and later. [#2963](https://github.com/BornToBeRoot/NETworkManager/pull/2963) +- Migrated code for some loading indicators from the library [LoadingIndicators.WPF] (https://github.com/zeluisping/LoadingIndicators.WPF) to the NETworkManager repo, as the original repo looks unmaintained and has problems with MahApps.Metro version 2 and later. [#2963](https://github.com/BornToBeRoot/NETworkManager/pull/2963) - Code cleanup & refactoring [#2940](https://github.com/BornToBeRoot/NETworkManager/pull/2940) - Language files updated via [#transifex](https://github.com/BornToBeRoot/NETworkManager/pulls?q=author%3Aapp%2Ftransifex-integration) - Dependencies updated via [#dependabot](https://github.com/BornToBeRoot/NETworkManager/pulls?q=author%3Aapp%2Fdependabot)