This is a little port scanner I made. It's pretty fast because it uses the timeout feature within the connect method.
Code:
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Trytohaxme
* @version 1.0
*
*/
public class Main implements Runnable {
private List<Integer> ports = new ArrayList<Integer>();
private String host = "put dam IP here.";
public static void main(String[] args) {
new Main();
}
public Main(){
new Thread(this).start();
}
public void run(){
for (int port = 1; port <= 65536; port++)
try {
Socket socket = new Socket();
socket.bind(null);
socket.connect(new InetSocketAddress(host, port), 140);
socket.close();
System.out.println("Port: "+port);
ports.add(port);
} catch (IOException ex) {
}
int portList = ports.size();
System.out.println("Total Ports: "+portList);
}
}