Created
May 13, 2019 03:32
-
-
Save theArjun/f4a456d1ce84132533b57f3830aeb5bc to your computer and use it in GitHub Desktop.
Checks if internet is Available on PC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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