Created
March 9, 2012 23:44
-
-
Save thefinn93/2009350 to your computer and use it in GitHub Desktop.
wat do
This file contains 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
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