PingChecker
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;
namespace MyApp.Utility
{
<summary>
</summary>
public class PingChecker
{
#region コンストラクタ
<summary>
</summary>
public PingChecker()
{
}
#endregion
#region メソッド
#region Pingを送信する
<summary>
</summary>
<param name="hostNameOrAddress"></param>
<param name="timeOut"></param>
<param name="repeatCount"></param>
<returns></returns>
public bool Send(string hostNameOrAddress, Int32 timeOut, Int32 repeatCount)
{
if (string.IsNullOrEmpty(hostNameOrAddress))
{
throw new ArgumentException("param:[hostNameOrAddress]がnullまたは空文字");
}
if (timeOut < 0)
{
throw new ArgumentException("param:[timeOut]が0未満");
}
if (repeatCount < 0)
{
throw new ArgumentException("param:[repeatCount]が0未満");
}
bool result = false;
using (Ping p = new Ping())
{
try
{
for (int i = 0; i < repeatCount; i++)
{
PingReply reply = p.Send(hostNameOrAddress, timeOut);
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
{
result = true;
break;
}
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex.ToString());
}
}
return result;
}
#endregion
#endregion
}
}