Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*author: _where
- * A port scanner that takes in three arguments, a host, a starting number for the port range, and the ending number in the range
- * tried this with the arguments - 10.199.212.2, 8079, 8081, and was connected to 8080.
- */
- import java.io.*;
- import java.net.*;
- public class PortScanner {
- public static void main(String[] args) throws FileNotFoundException
- {
- Socket connect = null; long t = 0; PrintStream output = new PrintStream("output.log");
- for (int i = Integer.parseInt(args[1]); i < Integer.parseInt(args[2]); i++)
- {
- try
- {
- t = System.currentTimeMillis(); connect = new Socket(InetAddress.getByName(args[0]), i);
- }
- catch(IOException e)
- {
- output.println("Connection could not be established on port - " + i + " after " + (System.currentTimeMillis() - t) + " ms");
- continue;
- }
- output.println("Connection established on port - " + i + " after " + (System.currentTimeMillis() - t) + " ms");
- try {
- if (connect != null)
- connect.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment