#region "Ping network"
///
/// Method determine if a remote computer is accessible over the network
///
///
private async void GetIPAddress(string ip)
{
IPAddress networkIP = await PingAsync(ip);
if (networkIP == null)
{
HostEntry = Dns.GetHostEntry(NetworkIPAddress);
foreach (IPAddress ipHost in HostEntry.AddressList)
{
if (ipHost.AddressFamily == AddressFamily.InterNetwork)
{
networkIP = ipHost;
NetworkIPAddress = networkIP.ToString();
Name = HostEntry.HostName;
}
}
}
Name = HostEntry?.HostName ?? ip;
NetworkIP = networkIP;
}
private async Task PingAsync(string ip)
{
if (IPAddress.TryParse(ip, out IPAddress networkIP))
{
using (Ping ping = new Ping())
{
PingReply replay = await ping.SendPingAsync(networkIP, 1000);
try
{
Name = replay.Status.ToString();
if (replay.Status == IPStatus.Success)
{
IsAvailable = true;
NetworkIPAddress = networkIP.ToString();
HostEntry = Dns.GetHostEntry(networkIP);
}
}
catch
{ }
}
}
return networkIP;
}
#endregion