Skip to content

Instantly share code, notes, and snippets.

@pablomatiasgomez
Created March 11, 2016 15:11
Show Gist options
  • Save pablomatiasgomez/f811bea71365ed3b70ae to your computer and use it in GitHub Desktop.
Save pablomatiasgomez/f811bea71365ed3b70ae to your computer and use it in GitHub Desktop.
Testing printer open ports
private static final String IP = "10.254.130.140";
public static void main(String[] args) throws UnknownHostException, IOException {
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "200");
IntStream.range(1, 64000).filter(LocaleResolver::testPort).forEach(System.out::println);
List<Integer> ports = Arrays.asList(5000, 5001, 4000, 8000, 9400, 79, 9200, 9500, 9501, 515, 9100, 9600, 6100, 6110);
ports.parallelStream().filter(LocaleResolver::testPrint).forEach(System.out::println);
}
private static boolean testPort(int port) {
try {
new Socket(IP, port).close();
} catch (IOException e) {
return false;
}
return true;
}
private static boolean testPrint(int port) {
try {
Socket socket = new Socket(IP, port);
DataOutputStream outToServer = new DataOutputStream(socket.getOutputStream());
outToServer.writeBytes(String.valueOf(port));
socket.close();
} catch (IOException e) {
System.out.println("Port " + port + " gave error: " + e.getMessage());
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment