using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.IO; namespace WmDataLinkMonitor { public partial class _default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string output = "
" + Environment.NewLine;

            foreach (string serverAddress in WmDataLinkMonitor.ServerAddresses) {
                string shortServerName = serverAddress.Replace("http://", "").Replace("/datalink/","");

                string response = "[ERROR] Could not connect to this server";
                string healthUrl = serverAddress+"?command=LINK_HEALTH";
                try {
                    response = getInternetResponse(healthUrl, 10000);
                } catch { }

                output += shortServerName + " - " + response + Environment.NewLine;

            }

            output += "
"; Response.Write(output); } /// /// Makes a request and returns the response in a string. /// /// URL to fetch. /// public static string getInternetResponse(string url, int timeoutMilliSeconds) { // used to build entire input System.Text.StringBuilder sb = new System.Text.StringBuilder(); // used on each read operation byte[] buf = new byte[8192]; // prepare the web page we will be asking for HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Referer = url; request.Timeout = timeoutMilliSeconds; request.UserAgent = "WmDataLinkMonitor"; // execute the request HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // we will read data via the response stream Stream resStream = response.GetResponseStream(); string tempString = null; int count = 0; do { // fill the buffer with data count = resStream.Read(buf, 0, buf.Length); // make sure we read some data if (count != 0) { // translate from bytes to ASCII text tempString = System.Text.Encoding.ASCII.GetString(buf, 0, count); // continue building the string sb.Append(tempString); } } while (count > 0); // any more data to read? return sb.ToString(); } } }