开发者

How to Get WebSite IP that doesn't Answer Pings?

I'm trying to get the IP address of a website that does not respond开发者_StackOverflow社区 to pings -- they time out.

I'm trying to do this from a C# application rather than the command entry screen in windows. I've been using the ping command which has times out on some sites so it is not useful there.

Is there another way to get this information that does not require the site to respond?


Even if the site does not respond to PINGs (ICMP not enabled on the server or filtered by firewall), the PING command should still resolve the site name into an IP address and display that IP address to you.

Check the output of a ping command on Windows (the ip address in bold):

ping wikipedia.org

Pinging wikipedia.org [208.80.152.2] with 32 bytes o
Reply from 208.80.152.2: bytes=32 time=245ms TTL=50
Reply from 208.80.152.2: bytes=32 time=235ms TTL=50

Update (due to to updated question)

If you are trying to get the IP address for DNS name from a C# application, you should use the GetHostEntry method from the Dns class: http://msdn.microsoft.com/en-us/library/ms143998.aspx .


You get IP from DNS, and need it to perform a ping, so you have it already.

$ ping google.com
PING google.com (74.125.227.51) 56(84) bytes of data.
64 bytes from 74.125.227.51: icmp_seq=0 ttl=56 time=5.80 ms
64 bytes from 74.125.227.51: icmp_seq=1 ttl=56 time=6.23 ms

The IP is shown. If you aren't getting an IP, your DNS might be down.

You can also try nslookup google.com


To get an IP address from a host name in Dns.GetHostEntry(). Pass in the host name and it will return you the IP address.

There is no reason you need to ping (on anyway contact) a site to get it's IP address. A DNS lookup will give you what you need.


You can use nslookup to resolve domain names.

nslookup google.com


The following code can be used to execute a DNS lookup for the supplied host name.

Using DNS will bypass accessing the target server. It is an independant distributed directory service that maintains hostname to IP address lookups.

The following code will give the first returned IP address for a host if a DNS entry can be resolved for the supplied host name.

    public void test()
    {
        string hostname = "google.com";
        IPAddress ipAdress;

        if (TryGetIpAddress(hostname, out ipAdress))
        {
            Console.WriteLine("Host:'{0}', IP:{1}.", hostname, ipAdress);
        }
        else
        {
            Console.WriteLine("Host '{0}' not found.", hostname);
        }
    }

    public bool TryGetIpAddress(string hostname, out IPAddress ipAddress)
    {
        const int HostNotFound = 11001;
        ipAddress = null;

        try
        {
            IPHostEntry hostEntry = Dns.GetHostEntry(hostname);

            ipAddress = hostEntry.AddressList[0];
        }
        catch (SocketException ex)
        {
            if (ex.ErrorCode != HostNotFound) throw;
        }

        return (ipAddress != null);
    } 


You can use tracert and it will resolve the IP address and tell you if it can be reached or where it stops.


If site (http) is up and running then it is very well clear that the sys/network admin disabled ping and most probably trace route utility too. It is getting very common now. See here. Your alternative is to use ns lookup or WHOIS service as described here


Doing this in code you should have some function like gethostbyname().

This should be on stackoverflow.com


untested

You could host this website

http://centralops.net/co/DomainDossier.aspx

you could use import.io to make functinality with the site.

https://www.import.io/

this links could give you an insight

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜