Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. public static bool PingHost(string nameOrAddress)
  2. {
  3. bool pingable = false;
  4. System.Net.NetworkInformation.Ping pinger = null;
  5.  
  6. try
  7. {
  8. pinger = new System.Net.NetworkInformation.Ping();
  9. System.Net.NetworkInformation.PingReply reply = pinger.Send(nameOrAddress, 100);
  10. pingable = reply.Status == System.Net.NetworkInformation.IPStatus.Success;
  11. }
  12. catch (System.Net.NetworkInformation.PingException)
  13. {
  14. // Discard PingExceptions and return false;
  15. }
  16. finally
  17. {
  18. if (pinger != null)
  19. {
  20. pinger.Dispose();
  21. }
  22. }
  23. return pingable;
  24. }
Add Comment
Please, Sign In to add comment