1

I am making a "health index" site that can display to system admins the health of our web & data servers.

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)
  3. Are specific windows services running that I expect?
  4. Does the web server have access to the internet?

I have written c# functions for 1-3 so far. However, I cannot figure out how to solve #4.

Basically, I want to determine if a remote web server has internet access. I don't want to just ping the server from my computer because that wont prove if it has internet access.

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.

Anyone know how I can use C# to determine if this remote web server has internet access?

Thanks

user952342
  • 2,602
  • 7
  • 34
  • 54
  • Are you allowed to put custom code on the server that pings the internet and then see those results somewhere? – Bill Gregg May 24 '13 at 14:50
  • Can you install a service on the remote machine? If so you could have the remote machine contact you and you know that it has a connection. – decompiled May 24 '13 at 14:51
  • Yes, I have full access to the server... but I'd rather not create a whole windows service to do this task. I was hoping there might be a simpler way. – user952342 May 24 '13 at 14:52
  • For example, in powershell, I can do it with 1 line of code like this: psexec \\MyWebServer ping www.google.com – user952342 May 24 '13 at 14:53
  • @user952342 you can run the powershell command using Process p = new Process() and parse the output. – decompiled May 24 '13 at 14:56
  • curious how you did steps #1-3 in c# without installing something (eg your c# app) on the remote machine? – wal May 24 '13 at 14:56

3 Answers3

0

You undoubtedly can do all those things but there are tools to manage this kind thing and a lot more.

Check out 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.

LoztInSpace
  • 5,584
  • 1
  • 15
  • 27
0

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);
decompiled
  • 1,853
  • 3
  • 14
  • 19
-2

Looks like someone has some code for this here:

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.

Community
  • 1
  • 1
Michael
  • 37
  • 7
  • thats too low level for what original poster wanted; gives no indication of connectivity to wider internet. – wal May 24 '13 at 14:58