Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static bool PingHost(string nameOrAddress)
- {
- bool pingable = false;
- System.Net.NetworkInformation.Ping pinger = null;
- try
- {
- pinger = new System.Net.NetworkInformation.Ping();
- System.Net.NetworkInformation.PingReply reply = pinger.Send(nameOrAddress, 100);
- pingable = reply.Status == System.Net.NetworkInformation.IPStatus.Success;
- }
- catch (System.Net.NetworkInformation.PingException)
- {
- // Discard PingExceptions and return false;
- }
- finally
- {
- if (pinger != null)
- {
- pinger.Dispose();
- }
- }
- return pingable;
- }
Add Comment
Please, Sign In to add comment