Jump to content

Difference between TCPNameToIP() and Ping()


Recommended Posts

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
Link to comment
Share on other sites

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.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...