From 07830df99d2b1aa2253e365007d8ee09a05059f6 Mon Sep 17 00:00:00 2001 From: Vincent BOUQUET Date: Sat, 17 Feb 2024 22:39:33 +0100 Subject: [PATCH] check ip interface before start --- MainForm.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/MainForm.cs b/MainForm.cs index f732e85..3c8b3fb 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,8 +1,11 @@ using System.ComponentModel; +using System.Diagnostics; using System.Net; +using System.Net.NetworkInformation; using System.Runtime.CompilerServices; using System.Web; using Tmds.MDns; +using Xamarin.Forms; namespace robospot_camera_finder { @@ -44,6 +47,33 @@ namespace robospot_camera_finder { InitializeComponent(); + bool got_proper_ip = false; + foreach (var net_interface in NetworkInterface.GetAllNetworkInterfaces()) + { + IPInterfaceProperties prop = net_interface.GetIPProperties(); + foreach (var ip in prop.UnicastAddresses) + { + if (ip.Address.ToString().StartsWith("10.")) + { + if (ip.IPv4Mask.ToString() == "255.0.0.0") + { + got_proper_ip = true; + } + } + } + } + if (!got_proper_ip) + { + DialogResult open_netsettings = MessageBox.Show("No Ethernet interface on the 10.0.0.0/8 subnet found. Cameras might not be detected. Do you want to open network settings ?", "Wrong IP configuration", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); + if (open_netsettings == DialogResult.Yes) + { + ProcessStartInfo startInfo = new ProcessStartInfo("NCPA.cpl"); + startInfo.UseShellExecute = true; + + Process.Start(startInfo); + } + } + browser.StartBrowse("_rtsp._tcp"); lbMain.DataSource = all_cameras;