【问题标题】:Check the availability of devices on the network [closed]检查网络上设备的可用性[关闭]
【发布时间】:2021-01-28 22:27:43
【问题描述】:

创建安装然后在后台运行的软件客户端(服务)的最佳方法是什么。当您打开设备(安装了该服务的位置)时,该服务会自动将设备的网络可用性信息发送到 Web 服务器。在网络服务器上将只是网络上设备的状态。 (开/关)

那么创建软件客户端的最佳解决方案是什么?使用 powershell、python 还是其他? 有没有人遇到过类似的问题?

【问题讨论】:

  • 你需要支持什么操作系统?
  • 我只需要支持windows

标签: python c# powershell


【解决方案1】:

如果只需要支持Windows,可以编写Windows Service(使用C#)。它会自动启动(您甚至不需要登录到 Windows),在服务启动时您可以发送“我正在运行”消息,并在停止时发送“我已关闭”消息。此外,该服务还可以响应来自服务器的“Are you on”请求。

这里有一个教程:https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer

发送消息非常简单(只需使用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;
}

【讨论】:

    【解决方案2】:

    我认为你应该看看像 Zabbix 这样的工具。使用该工具,您可以以不同的方式监控网络资源。我用它来监控企业网络和重要设备,你甚至可以创建一个可视化的地图来显示每个设备的状态。

    SNMP(简单网络管理协议)涵盖了您打算做的事情。 如果你能告诉我更多关于你期望做什么的细节,我可以给你更多建议......

    【讨论】:

    • 感谢您提供监控软件,但我想创建一个软件客户端。打开安装了软件的设备后,它将设备的状态发送到 Web 应用程序。 Web 应用程序将显示设备(安装软件的设备)及其状态。我认为在服务中使用 arp 协议比较合适。
    猜你喜欢
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多