You are on page 1of 1

Web Service

Retrieve Server IP Address


[WebMethod(Description="Get Server IP Address")]
public string GetServerIPAddress()
{
// used to build entire input
StringBuilder sb = new StringBuilder();

// used on each read operation


byte[] buf = new byte[8192];

HttpWebRequest request =
(HttpWebRequest)WebRequest.Create("http://www.network-tools.com");

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 = Encoding.ASCII.GetString(buf, 0, count);

// continue building the string


sb.Append(tempString);
}
}
while (count > 0); // any more data to read

String __SearchString =
"<input id=\"field\" name=\"host\" type=\"text\" value =\"(.*)\" size=\"85\" />";

System.Text.RegularExpressions.Regex _regex =
new System.Text.RegularExpressions.Regex(__SearchString);

return _regex.Match(sb.ToString()).Result("$1").ToString();
}

You might also like