c# - 在静态 IP 上连续 Ping,如果返回 false,则发送电子邮件
问题描述
我陷入了混乱,所以敲了社区的门。我需要制作一个程序,通过它我需要static IP
不断地点击特定地址(业务需要)。如果任何时候特定 IP 地址没有回复,我需要向服务器关闭的上级部门发送紧急电子邮件。
我需要问一些问题,哪一个适合这个东西?
控制台应用程序可以完成我的工作吗?
我怎样才能让我的控制台应用程序一直运行和点击?
我应该使用循环连续命中的方法是什么
我尝试使用 for 循环,但遇到了一些问题,当我运行下面的代码时,问题是returning false like after every 25 requests
什么return false 1 time
?
public static bool PingHost(string nameOrAddress)
{
bool pingable = false;
Ping pinger = null;
try
{
pinger = new Ping();
PingReply reply = pinger.Send(nameOrAddress);
pingable = reply.Status == IPStatus.Success;
}
catch (PingException)
{
// send email something went wrong please check
}
finally
{
if (pinger != null)
{
pinger.Dispose();
}
}
return pingable;
}
static void Main(string[] args)
{
int count; ;
string address = "ip-adress";
for(count = 1; count >0; count++ )
{
bool response = PingHost(address);
if (response)
{
Console.WriteLine("Ping successfull " + address);
}
else
{
// send email that server is down.
}
}
Console.ReadLine();
}
解决方案
推荐阅读
- r - 在while循环中使用R闪亮服务器控制循环执行
- laravel - Laravel 7:使失败的验证响应 200 而不是 422
- laravel - 一个模型包含两个相同类型的关系?
- java - Kubernetes 无法识别 SRV 类型 URI
- asp.net - 客户端的客户端密码验证失败,授权代码流上的客户端密码无效
- python - python 3中使用嵌套重复结构的双菱形结构
- javascript - Nativescript - Filterselect,RadListView。我用哪一个?
- python - 蓝牙:bluetooth_adapter_winrt.cc 获取默认适配器失败
- java - 如何拦截 Hotspot JVM 中的内存访问/更改?
- rust - 如何在 rust 中返回链式迭代器