Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- class PortScanner
- {
- public static void main(String [] args)
- {
- int start = 0;
- int end = 65535;
- String hostname = "localhost";
- if(args.length > 0)
- hostname = args[0];
- if(args.length > 1)
- start = Integer.parseInt(args[1]);
- if(args.length > 2)
- end = Integer.parseInt(args[2]);
- for(int port = start; port <= end; port++)
- {
- try
- {
- Socket socket = new Socket();
- socket.connect(new InetSocketAddress(hostname, port), 1);
- socket.close();
- System.out.println("Port " + port + " is open.");
- }
- catch (Exception ex)
- {
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement