Port Scanner with Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
try
    {
        String host = "server-box";
        InetAddress addr = InetAddress.getByName(host);
        System.out.println("Scanning for open ports on "+"\""+host+"\""+"...");
        for(int i = 0; i < 65536; i++)
        {
            try
            {
                Socket s = new Socket(host, i);//trying to open connection
                System.out.println("port "+i+" open!");//we found open port
                s.close();//closing port
            }
            catch(IOException e){  }
        }
    }
    catch(UnknownHostException a)
    {
        System.out.println(a);
    }
Share This!

Leave a Reply

Your email address will not be published.