|
10 | 10 | using System.Windows.Input; |
11 | 11 | using log4net; |
12 | 12 | using NetworkInterface = NETworkManager.Models.Network.NetworkInterface; |
| 13 | +using System.Net.Sockets; |
13 | 14 |
|
14 | 15 | namespace NETworkManager.ViewModels; |
15 | 16 |
|
@@ -760,6 +761,14 @@ private Task CheckConnectionComputerAsync(CancellationToken ct) |
760 | 761 | await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( |
761 | 762 | IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv4Address)); |
762 | 763 |
|
| 764 | + if (detectedLocalIPv4Address == null) |
| 765 | + { |
| 766 | + Log.Debug("CheckConnectionComputerAsync - Local IPv4 address detection via routing failed, trying network interfaces..."); |
| 767 | + |
| 768 | + detectedLocalIPv4Address = await NetworkInterface.DetectLocalIPAddressFromNetworkInterfaceAsync( |
| 769 | + AddressFamily.InterNetwork); |
| 770 | + } |
| 771 | + |
763 | 772 | if (detectedLocalIPv4Address != null) |
764 | 773 | { |
765 | 774 | Log.Debug("CheckConnectionComputerAsync - Local IPv4 address detected: " + detectedLocalIPv4Address); |
@@ -787,6 +796,14 @@ await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( |
787 | 796 | await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( |
788 | 797 | IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv6Address)); |
789 | 798 |
|
| 799 | + if (detectedLocalIPv6Address == null) |
| 800 | + { |
| 801 | + Log.Debug("CheckConnectionComputerAsync - Local IPv6 address detection via routing failed, trying network interfaces..."); |
| 802 | + |
| 803 | + detectedLocalIPv6Address ??= await NetworkInterface.DetectLocalIPAddressFromNetworkInterfaceAsync( |
| 804 | + AddressFamily.InterNetworkV6); |
| 805 | + } |
| 806 | + |
790 | 807 | if (detectedLocalIPv6Address != null) |
791 | 808 | { |
792 | 809 | Log.Debug("CheckConnectionComputerAsync - Local IPv6 address detected: " + detectedLocalIPv6Address); |
@@ -896,6 +913,9 @@ private Task CheckConnectionRouterAsync(CancellationToken ct) |
896 | 913 | await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( |
897 | 914 | IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv4Address)); |
898 | 915 |
|
| 916 | + detectedLocalIPv4Address ??= await NetworkInterface.DetectLocalIPAddressFromNetworkInterfaceAsync( |
| 917 | + AddressFamily.InterNetwork); |
| 918 | + |
899 | 919 | if (detectedLocalIPv4Address != null) |
900 | 920 | { |
901 | 921 | Log.Debug("CheckConnectionRouterAsync - Computer IPv4 address detected: " + detectedLocalIPv4Address); |
@@ -939,6 +959,9 @@ await NetworkInterface.DetectGatewayFromLocalIPAddressAsync( |
939 | 959 | await NetworkInterface.DetectLocalIPAddressBasedOnRoutingAsync( |
940 | 960 | IPAddress.Parse(SettingsManager.Current.Dashboard_PublicIPv6Address)); |
941 | 961 |
|
| 962 | + detectedComputerIPv6 ??= await NetworkInterface.DetectLocalIPAddressFromNetworkInterfaceAsync( |
| 963 | + AddressFamily.InterNetworkV6); |
| 964 | + |
942 | 965 | if (detectedComputerIPv6 != null) |
943 | 966 | { |
944 | 967 | Log.Debug("CheckConnectionRouterAsync - Computer IPv6 address detected: " + detectedComputerIPv6); |
|
0 commit comments