Problems with Ping on Android

Hey,

For my Android media app I'm trying to detect a WebDAV server that is being run locally - It's a media server that runs over HTTP basically.

For this, I get the subnet (i.e 192.168.1.) then ping every IP in that subnet with multiple threads using Tasks.
With IPs that respond I then filter again.

In the editor this works:

System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();

        for (int i = 2; i < 255; i++)
        {   
            string ip = $"{subnet}.{i}";
            var task = PingSubnetAsync(ping, ip);
        }
( ... )
private async Task PingSubnetAsync(System.Net.NetworkInformation.Ping ping, string ip)
    {
        await Task.Run(() =>
        {
            PingReply reply = ping.Send(ip, 100);

            if (reply.Status == IPStatus.Success)
            {
                try
                {
                    IPHostEntry host = Dns.GetHostEntry(IPAddress.Parse(ip));
                    UnityEngine.Debug.Log($"{ip}, {host.HostName}, Up\n");
                    lock(lockObj){
                        ipToHostname.Add(ip, host.HostName);
                    }

                }
                catch
                {
                    UnityEngine.Debug.LogError($"Couldn't retrieve hostname from {ip}");
                    lock(lockObj){
                        ipToHostname.Add(ip, "Unknown");
                    }
                }
            }
        });
    }

Problem is in Android the Task stalls indefinitely - No exceptions or errors are thrown either.
Any ways to fix this, or just another approach to do the same would be great.

I tried using UnityEngine.Ping instead but it does not have a method to identify failed Pings.

Does it work single threaded? Try that first to see if the issue is with multithreading or the ping code.

Yes, same issue single threaded, works only on the editor and in Android it errors out without showing any Exception.
I managed to use UnityEngine.Ping though, if the ping is successful then ping.time is greater than 0.

Thanks for the reply