0% found this document useful (0 votes)
48 views1 page

Web Service To Get Web IP Address

The document describes a web service method called GetServerIPAddress that retrieves the server's IP address by making an HTTP request to a specified URL. It reads the response stream, collects the data into a string, and uses a regular expression to extract the IP address from the HTML input field. The method returns the extracted IP address as a string.

Uploaded by

ericdecoff
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC or read online on Scribd
0% found this document useful (0 votes)
48 views1 page

Web Service To Get Web IP Address

The document describes a web service method called GetServerIPAddress that retrieves the server's IP address by making an HTTP request to a specified URL. It reads the response stream, collects the data into a string, and uses a regular expression to extract the IP address from the HTML input field. The method returns the extracted IP address as a string.

Uploaded by

ericdecoff
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC or read online on Scribd

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)[Link]("[Link]

HttpWebResponse response = (HttpWebResponse)[Link]();

// we will read data via the response stream


Stream resStream = [Link]();

string tempString = null;


int count = 0;

do
{
// fill the buffer with data
count = [Link](buf, 0, [Link]);

// make sure we read some data


if (count != 0)
{
// translate from bytes to ASCII text
tempString = [Link](buf, 0, count);

// continue building the string


[Link](tempString);
}
}
while (count > 0); // any more data to read

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

[Link] _regex =
new [Link](__SearchString);

return _regex.Match([Link]()).Result("$1").ToString();
}

You might also like