Created
August 19, 2016 15:52
-
-
Save aolle/678c923fd61e4e00bfd09ab4feac9295 to your computer and use it in GitHub Desktop.
Check socket - Java
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
| import java.net.*; | |
| public class Nc { | |
| public static void main(String[] args){ | |
| if(args.length < 2) | |
| return; | |
| String host = args[0]; | |
| int port = Integer.parseInt(args[1]); | |
| String msg = "Port " + port + " from " + host; | |
| try { | |
| Socket socket = new Socket(host, port); | |
| System.out.println(msg + " opened."); | |
| socket.close(); | |
| } catch (Exception e) { | |
| System.out.println(msg + " closed."); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment