简单的端口扫描器

端口扫描。
可以告诉你目标host下面的哪些端口在运行服务,目标host下有哪些闲置端口。

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

public class LowPortScanner {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String host = "localhost";
        
        if (args.length > 0)
        {
            host = args[0];
        }
        
        for (int i = 1; i < 10; i++)
        {
            try
            {
                Socket s = new Socket(host, i);
                System.out.println("there is a server on port " + i + " of " + host);
                
            }
            catch (UnknownHostException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
                System.err.println(e);
                break;
            }
            catch (IOException e)
            {
            }
        }
        System.out.println("END.");
    }

}

猜你喜欢

转载自lot-of-mine.iteye.com/blog/1420624
今日推荐