I want to know the best way to identify if the internet is working or not. I was thinking of Ping, but maybe the target is down this will make my application think that the internet is down.
So if anyone got any idea, it would be great to share.
I want to know the best way to identify if the internet is working or not. I was thinking of Ping, but maybe the target is down this will make my application think that the internet is down.
So if anyone got any idea, it would be great to share.
Rather than picking a host or DNS to ping, try pinging the web resource you intend to interact with. Or, rather than ping, actually try to interact with that endpoint and thoroughly prepare for a situation where that host cannot be reached.
I.E. a twitter client might try to connect to twitter.com and if it can't (whether they have no internet connection or twitter.com is blocked) the program could report "Twitter is currently unreachable".
Ping a working DNS Like 4.2.2.4
,4.2.2.3
,4.2.2.2, 8.8.8.8, 8.8.4.4
Ping myPing = new Ping();
String host = "4.2.2.4;
byte[] buffer = new byte[32];
int timeout = 1000;
PingOptions pingOptions = new PingOptions();
PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
if (reply.Status == IPStatus.Success) {
// presumably online
}