Your code will never be reliable. The server may stop answering to your PING for any reason (it is off for maintenance, it is victim of a DOS attack, its network cards are not functioning properly, its firewall rules have been changed to block the ICM protocol, its electrical sources are down, etc.) and lead you to think that you're not connected to Internet, which is wrong. That's less the case, of course, with server farms behind the same IP, which are supposed to be always up, but you generate an useless traffick to these servers and it may happen that you're unable to reach them anyway due to a DNS failure for example (one of my servers is still unreachable for this reason). I admit that pinging google.com will help you to decide with a high probability whether you're connected or not but Google may become bored at some time to be the target of millions of ICMP requests and start blocking them... Moreover, between the time where you check the server and the time where you really want to use the network, many things can occur and the "connected/unconnected" status may become wrong. So, to my eyes, checking a server to know whether you're connected or not is at worst unreliable, at best useless. If you want to use a remote resource/service, connect to it. What's the usefulness of pinging a server (especially a different server than the one you want to connect) some minutes ago ?