Skip to content

Instantly share code, notes, and snippets.

@thefinn93
Created March 9, 2012 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefinn93/2009350 to your computer and use it in GitHub Desktop.
Save thefinn93/2009350 to your computer and use it in GitHub Desktop.
wat do
package portscanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Scanner;
public class PortScanner {
public static String connect(String host, int port) {
String output = null;
try {
Socket connection = new Socket(host,port);
connection.setSoTimeout(1000);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
output = in.readLine();
connection.close();
} catch (UnknownHostException e) {
output = "Unknown host: " + host;
} catch (IOException e) {
output = "Closed";
}
return output;
}
public static void main(String args[]) {
Scanner inputz = new Scanner(System.in);
System.out.print("What host would you like to scan: ");
String host = inputz.nextLine();
System.out.println("Scanning ports 1-65535 on " + host);
for(int port = 1; port < 65536; port++) {
System.out.println("Port " + port + ":\t" + connect(host,port));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment