1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public static bool IsJoinable(string host)
{
if (System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
if (host.IndexOf(':') != -1)
{
host = host.Substring(0, host.IndexOf(":"));
}
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
return ping.Send(host, 1000).Status == IPStatus.Success;
}
catch (Exception)
{
return false;
}
}
else
{
return false;
}
}
public static bool IsOnNetwork()
{
try
{
bool onNetwork = true;
foreach (System.Net.IPAddress Listip in System.Net.Dns.GetHostEntry(Environment.MachineName).AddressList)
{
if (Listip.ToString() == "127.0.0.1")
{
onNetwork = false;
}
}
if (onNetwork)
{
return true;
}
else
{
return false;
}
}
catch (Exception)
{
return false;
}
} |
Partager