diff --git a/src/WOL/WOL.Android/MainActivity.cs b/src/WOL/WOL.Android/MainActivity.cs index 1e9de33..6962196 100644 --- a/src/WOL/WOL.Android/MainActivity.cs +++ b/src/WOL/WOL.Android/MainActivity.cs @@ -157,16 +157,23 @@ private async void ShowScanDialog() var token = scanCTS.Token; Task t1 = Task.Run(() => { - NetworkManager.GetNetworkIpAndMask(out IPAddress ip, out IPAddress sub); - var networkAddress = NetworkManager.CalNetworkAddress(ip, sub).ToString(); - networkAddress = networkAddress.Substring(0, networkAddress.Length - 1); + try + { + NetworkManager.GetNetworkIpAndMask(out IPAddress ip, out IPAddress sub); + var networkAddress = NetworkManager.CalNetworkAddress(ip, sub).ToString(); + networkAddress = networkAddress.Substring(0, networkAddress.Length - 1); - for (int i = 2; i <= 254; i = i + 1) + for (int i = 2; i <= 254; i = i + 1) + { + string addr = $"{networkAddress}{i}"; + UdpClient udp = new UdpClient(addr, 23452); + udp.Send(new byte[] { 0 }, 1); + ScaningDetail.Text = addr; + } + } + catch (Exception) { - string addr = $"{networkAddress}{i}"; - UdpClient udp = new UdpClient(addr, 23452); - udp.Send(new byte[] { 0 }, 1); - ScaningDetail.Text = addr; + } }, token);