Get site server from IP address

I have a function that returns the site server when entering 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 would also like to get the site server from the IP address instead of the site URL. But if I specify the IP address, I get the error "Invalid URI: URI format could not be determined." when calling WebRequest.Create (url).

Does anyone know how I can change this to accomplish what I want?

+4
source share
3 answers

Otherwise, you can find the name from the IP address, and then use the address in your other calls:

 System.Net.Dns.GetHostEntry("127.0.0.1").HostName.ToString() 
+2
source

Do you use this method when using an IP address? This error will be reset if you do not have "http: //" appended to the IP address.

+1
source

One IP can serve several domains. You will not have a 1: 1 display. What you are trying to do is reverse DNS lookups. There are many web services that provide an incomplete list of domains served from an IP address. As soon as I had to use a combination of them to get a more complete list.

Here is a short list of such sites:

And I already used the following DNS lookup, which also finds other domains served by the same IP:

+1
source

Source: https://habr.com/ru/post/1307554/


All Articles