Leo1906

Difference between TCPNameToIP() and Ping()

5 posts in this topic

#1 ·  Posted (edited)

Hi there :)

I am trying to check wether a certain host is online or not. So far I just used Ping to do so. Since Ping needs at least the time specified in timeout if a host is unreachable, I was wondering if the same could be done with TCPNameToIP()?

For me it seems that this function is a lot quicker checking a host. If the name can't be translated to an IP it throws an error. So if the host is unreachable I should get an error .. right?

The bad thing about Ping is that the Thread is blocked until the timeout is reached (in case of an unreachable host). This wont happen if you use TCPNameToIP().

 

So are my thoughts correct? I don't need the detailed informations Ping returns, only if the host is online or offline ..

 

Edit: or does TCPNameToIP() also uses local cached DNS -systems? So that it remembers the Name to IP conversion in one Windows session? But even this won't be that bad ..

Edited by Leo1906

Share this post


Link to post
Share on other sites



#2 ·  Posted

by using TCPNameToIP() you are actually trying to check host status by querying the DNS service. this is obviously wrong. a DNS service maintains a DNS record even when the host is not alive for a while. and it does not bother to check the host in order to reply to a DNS query.

to check if a host is online, you must check if the host is online, not if the DNS service is online. use ping for the simplest test, and if the host is configured to ignore ping (for security reasons), you can alternatively check a vital service that the host provides.

1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted

Ok but then TCPNameToIP() could be used to check the internet connection in general ..?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Ping is still probably the best better option.  You could have live DNS servers which will resolve hostnames/IPs, but the destination host still be offline.

Edited by spudw2k

Share this post


Link to post
Share on other sites

#5 ·  Posted

TCPNameToIP resolves the host name with a DNS query. A DNS resolution does not require an internet connection : so, no, TCPNameToIP cannot be used to check the Internet connection.

Look at InternetGetConnectedState here : https://www.autoitscript.com/wiki/Connected, it's a sure way

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now