创建安装并在后台运行的软件客户端(服务)的最佳方法是什么。当您打开设备(安装了服务的设备)时,此服务将自动将设备的网络可用性信息发送到Web服务器。在Web服务器上将仅是网络上设备的状态。 (打开/关闭)
那么创建软件客户端的最佳解决方案是什么?使用Powershell,Python或其他工具? 您有遇到类似问题的经验吗?
答案 0 :(得分:0)
我认为您应该看看Zabbix之类的工具。使用该工具,您可以以不同方式监视网络资源。我用它来监视企业网络和重要设备,甚至可以创建一个直观的地图来显示每个设备的状态。
SNMP(简单的网络管理协议)涵盖了您打算做的事情。 如果您可以告诉我更多有关您期望做什么的详细信息,我可以为您提供更多建议...
答案 1 :(得分:0)
如果仅需要支持Windows,则可以编写Windows服务(使用C#)。它会自动启动(您甚至不需要登录Windows),在服务启动时,您可以发送“我在”消息,而在停止时“我在关闭”消息。此服务还可以响应服务器上的“您在吗”请求。
发送消息非常简单(只需使用HttpClient
),接收消息就比较复杂。
您需要创建一个侦听器:
var listener = new HttpListener
{
AuthenticationSchemes = AuthenticationSchemes.Basic,
Prefixes =
{
ConfigurationManager.AppSettings["url"]
}
};
然后您需要收听消息:
listener.Start();
while (true)
{
HttpListenerContext context = await listener.GetContextAsync();
if (ValidateCredentials(context))
{
continue;
}
string body = new StreamReader(context.Request.InputStream).ReadToEnd().ToLower();
ProcessAction(body);
}
如果需要,还可以验证凭据:
bool ValidateCredentials(HttpListenerContext context)
{
var identity = (HttpListenerBasicIdentity)context.User.Identity;
Debug.WriteLine($"-u {identity.Name} -p {identity.Password}");
string user = ConfigurationManager.AppSettings["user"];
string password = ConfigurationManager.AppSettings["password"];
if (identity.Name != user || identity.Password != password)
{
return false;
}
return true;
}