Question:

Is there any method in c++/vc++/mfc so that I can verify whether remote machine is on network or not. I don't want to use ping command. I tried to use WSAConnect method but it takes lot of time in searching if remote machine is not on network. In that case application windoe freezes for long time. I need alternate way to verify remote machine netwotk connectivity. Plz help

Solution:1

You can check to see if a host name exists and if DNS can resolve an IP address for it, but this won't tell you if it's online. In order to determine if it's online, you must exchange data with the host. For this to happen the host must be listening on a port, and must send some sort of response.

Generally, the lowest common denominator for hosts is the ICMP packet - aka ping. You can write your own service in C++ to send these UDP packets, and detect a reply.

Some hosts and some routers disable ICMP to appear 'invisible'. If you know that your host accepts connections on a TCP port, you can attempt to create a tcp socket. For example, from a shell you can test using nc

If you do raw socket programming, you can attempt to connect to a host via, and then call select() with a short timeout.

Solution:2

If you don't want your app to block, use a thread.

Solution:3

you can use tracert command example:

tracert -w 1000 192.168.0.77

Solution:4

If the only issue is that calling WSAConnect locks up your UI, you can try calling it in nonblocking mode.

Call WSAEventSelect to set the socket to nonblocking mode prior to calling WSAConnect. You then call WSAAsyncSelect or WSAEventSelect to check the status of the connection.

MSDN's page on WSAConnect has some remarks about nonblocking mode here.

Solution:5

You can check if the machine is connected to a network, but without trying to transmit data to a site residing on the internet I don't think there is a way to check if that network is actually online. For example your end user might as well be connected to a DSL router which is not online at the moment.

Solution:6

You can use arping for it.

Also some smart switch can talk about attached host.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com