Skip to content

Commit

Permalink
catch auto scan exception
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhangGaoxing committed Aug 20, 2018
1 parent 73c5a83 commit e127982
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/WOL/WOL.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit e127982

Please sign in to comment.