I have a function that returns a website's server when you enter the url for the site:
private string GetWebServer()
{
string server = string.Empty;
//get URL
string url = txtURL.Text.Trim().ToLower();
if (!url.StartsWith("http://") && !url.StartsWith("https://"))
url = "http://" + url;
HttpWebRequest request = null;
HttpWebResponse response = null;
try
{
request = WebRequest.Create(url) as HttpWebRequest;
response = request.GetResponse() as HttpWebResponse;
server = response.Headers["Server"];
}
catch (WebException wex)
{
server = "Unknown";
}
finally
{
if (response != null)
{
response.Close();
}
}
return server;
}
I'd like to also be able to get a website's server from the IP address instead of the site's url. But if I enter an IP address, I get an error saying "Invalid URI: The format of the URI could not be determined." when calling WebRequest.Create(url).
Does someone know how I can modify this to accomplish what I want?