Skip to content

Instantly share code, notes, and snippets.

@aolle
Created August 19, 2016 15:52
Show Gist options
  • Select an option

  • Save aolle/678c923fd61e4e00bfd09ab4feac9295 to your computer and use it in GitHub Desktop.

Select an option

Save aolle/678c923fd61e4e00bfd09ab4feac9295 to your computer and use it in GitHub Desktop.
Check socket - Java
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