简体   繁体   English

使用C#检查远程服务器上的Internet连接

[英]Using C# to check for an internet connection on a remote Server

I am making a "health index" site that can display to system admins the health of our web & data servers. 我正在制作一个“健康指数”网站,该网站可以向系统管理员显示我们的Web和数据服务器的运行状况。

Some of the metrics I am measuring are: 我正在衡量的一些指标是:

  1. How much disk space does the server have? 服务器有多少磁盘空间?
  2. Is the server on? 服务器在吗? (can I ping it from my PC) (我可以从PC上ping吗?)
  3. Are specific windows services running that I expect? 我是否正在运行特定的Windows服务?
  4. Does the web server have access to the internet? Web服务器可以访问互联网吗?

I have written c# functions for 1-3 so far. 到目前为止,我已经为1-3编写了c#函数。 However, I cannot figure out how to solve #4. 但是,我不知道如何解决#4。

Basically, I want to determine if a remote web server has internet access. 基本上,我想确定远程Web服务器是否可以访问Internet。 I don't want to just ping the server from my computer because that wont prove if it has internet access. 我不想仅通过计算机对服务器执行ping操作,因为这无法证明服务器是否可以访问互联网。

This web server primarily serves an "Intranet" website... so, I can't prove that the server has internet by simply going to the site it serves in a browser. 该Web服务器主要为“ Intranet”网站提供服务...因此,仅通过浏览器即可访问其服务的网站,我无法证明该服务器具有Internet。

Anyone know how I can use C# to determine if this remote web server has internet access? 有谁知道我如何使用C#确定此远程Web服务器是否可以访问Internet?

Thanks 谢谢

You undoubtedly can do all those things but there are tools to manage this kind thing and a lot more. 毫无疑问,您可以做所有这些事情,但是有一些工具可以管理此类事情。

Check out SCOM. 签出SCOM。 It allows you to use tons of out-of-the-box checks, add your own and roll up complex networks of servers to an easy to use dashboard, alerting and reporting system. 它允许您使用大量现成的检查,添加自己的检查以及将复杂的服务器网络汇总到易于使用的仪表板,警报和报告系统中。

It's not free, but if you have servers, you probably have some kind of license towards it. 它不是免费的,但是如果您有服务器,则可能拥有某种许可证。 It's quite possibly cheaper than writing your own stuff and almost certainly more thorough, robust and will have more coverage than you will ever be able to write on your own. 它可能比编写自己的东西便宜,而且几乎可以肯定更彻底,更强大,而且覆盖范围比您自己能够编写的要多。

It may not be the answer you were looking for, but check it out. 它可能不是您要找的答案,但请检查一下。

Untested, but something like this: 未经测试,但是像这样:

var p = new Process
            {
                StartInfo =
                    {
                        UseShellExecute = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError = true,
                        RedirectStandardInput = true,
                        FileName = @"C:\path\to\PSTools\PsExec.exe",
                        Arguments = @"\\server cmd.exe ping www.google.com"
                    }
            };
        p.Start();

        string output = p.StandardOutput.ReadToEnd();
        string errormessage = p.StandardError.ReadToEnd();

        p.WaitForExit();

        Console.WriteLine(output);
        Console.WriteLine(errormessage);

Looks like someone has some code for this here: 看起来有人在这里有一些代码:

https://stackoverflow.com/a/2521961/1759812 https://stackoverflow.com/a/2521961/1759812

Handles checking the connection as well as handling loopbacks and other such items. 处理检查连接以及处理回送和其他此类项目。 This is for the server itself, not sure if you can grab this info remotely. 这是针对服务器本身的,不确定是否可以远程获取此信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM