Skip to content

Instantly share code, notes, and snippets.

@theArjun
Created May 13, 2019 03:32
Show Gist options
  • Select an option

  • Save theArjun/f4a456d1ce84132533b57f3830aeb5bc to your computer and use it in GitHub Desktop.

Select an option

Save theArjun/f4a456d1ce84132533b57f3830aeb5bc to your computer and use it in GitHub Desktop.
Checks if internet is Available on PC
/* This program checks whether your device is connected to Internet or not. */
import java.net.InetSocketAddress;
import java.net.Socket;
/**
* @author arjun
*/
public class IsInternetAvailable {
public static void main(String[] args) {
Socket sock = new Socket() ;
InetSocketAddress address = new InetSocketAddress("www.thearjun.tech", 80);
try{
sock.connect(address, 3000);
System.out.println("Active Internet Connection");
sock.close();
}
catch(Exception exc) {
System.out.println("No Internet Connection");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment