import java.io.IOException; import java.net.Inet4Address; import java.net.InetAddress; import java.net.Socket; import java.net.UnknownHostException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class PScan { protected final static int MAX_PORTS = (int)Character.MAX_VALUE; protected static InetAddress TARGET; /** * @param args the command line arguments */ public static void main(String[] args) { String host = (args.length == 1)? args[0] : "localhost"; try{ TARGET = Inet4Address.getByName(host); }catch(UnknownHostException uh){ System.out.println("Unknow Host --> "+host); System.exit(-1); } ExecutorService exs = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1); System.out.println("Scanning host " + TARGET.getHostAddress()); for(int i = 1; i <= MAX_PORTS; i++){ exs.submit(new Scan(i)); } exs.shutdown(); } } class Scan implements Runnable{ private int port_number; public Scan(int pn){this.port_number = pn;} public void run(){ Socket sock = null; try{ sock = new Socket(PScan.TARGET, port_number); System.out.println("The port "+port_number+" is open"); }catch(IOException ioe){ } if(port_number == PScan.MAX_PORTS){ System.out.println("Last port reached"); } } }
Sabtu, Ogos 03, 2013
Java : port scanner (multithread)
Langgan:
Catat Ulasan (Atom)
0 ulasan:
Catat Ulasan
Selamat datang ke 0x2013LΣΣT. Sekiranya anda mempunyai persoalan, pandangan, permintaan, bantuan, cadangan dan sebagainya. Tinggalkan pesanan anda ke dalam kotak komen. Terima kasih !
- http://0x2013.blogspot.com -