Port Scanner

Description

The application scans a range of TCP ports for services on the hosts belonging to a specified range of IP addresses (IPv4 or IPv6).

The application main entry point PortScanner.main() parses command line arguments and starts the single instance of the PortScanner class.

The instance of PortScanner class maintains pool of end-points (= IP address + TCP port) to be scanned. It also starts worker threads (that should scan end-points from the pool) and displays progress to the user.

The PortConnect class encapsulates port scanning worker thread. The thread retrieves end-points from the owner's pool and reports (with a call-back) what was found on the particular end-point.

TCP port names are retrieved using instances of the ServiceNames class.

The RawIpAddress class encapsulates arithmetics for raw IPv4/v6 addresses.

Usage

    $ java -jar portScan.jar
    
    Usage: java -jar portScan.jar startAddr stopAddr startPort stopPort resultFile 

The application will ensure that startAddr is <= stopAddr and that startPort <= stopPort (i.e. it will swap addresses and/or ports).

Note, however, that startAddr and stopAddr must belong the same IP version:

    $ java -jar portScan.jar  2001:0db8:0000:0000:0000:0000:1428:0700 192.168.5.10 1 10 r.txt
    
    Error: The first and last IP addresses must be of the same IP version 

Executable

The jar file of the package can be found here.

Source Files

Examples

    
    $ java -jar portScan.jar  10.0.1.255 10.0.1.1  1024 1  results.txt
    
    Warning: The first IP address is greater than the last IP address.
    Swapping IP addresses...
    
    Warning: The first TCP port is greater than the last TCP port.
    Swapping TCP ports...
    
    Scanning 255 hosts * 1024 ports/host = total 261120 end-points...
    ...
    
    $ java -jar portScan.jar  10.0.1.27 10.0.1.27  1  1024 results.txt
    
    Scanning 1 hosts * 1024 ports/host = total 1024 end-points...
    Elapsed 21 sec; Scanned 1024 of 1024 end-points (16 alive + 1008 dead); 0 threads active
    Completed.   

The sample results:

    2010-11-22 15:13:15.265 Started...
    
    2010-11-22 15:13:15.484 Connected: /10.0.1.27:25 (smtp), Thread 60, Elapsed 6 ms
    2010-11-22 15:13:15.500 Connected: /10.0.1.27:21 (ftp), Thread 44, Elapsed 24 ms
    2010-11-22 15:13:15.531 Connected: /10.0.1.27:110 (pop3), Thread 220, Elapsed 0 ms
    2010-11-22 15:13:15.546 Connected: /10.0.1.27:119 (nntp), Thread 250, Elapsed 1 ms
    2010-11-22 15:13:15.578 Connected: /10.0.1.27:143 (imap), Thread 294, Elapsed 25 ms
    2010-11-22 15:13:15.578 Connected: /10.0.1.27:22 (ssh), Thread 56, Elapsed 105 ms
    2010-11-22 15:13:15.578 Connected: /10.0.1.27:53 (domain), Thread 114, Elapsed 80 ms
    2010-11-22 15:13:15.734 Connected: /10.0.1.27:465 (smtps), Thread 912, Elapsed 5 ms
    2010-11-22 15:13:15.781 Connected: /10.0.1.27:563 (nntps), Thread 1118, Elapsed 1 ms
    2010-11-22 15:13:15.781 Connected: /10.0.1.27:587 (submission), Thread 1168, Elapsed 0 ms
    2010-11-22 15:13:15.921 Connected: /10.0.1.27:80 (http), Thread 170, Elapsed 398 ms
    2010-11-22 15:13:16.062 Connected: /10.0.1.27:995 (pop3s), Thread 1978, Elapsed 1 ms
    2010-11-22 15:13:16.062 Connected: /10.0.1.27:993 (imaps), Thread 1972, Elapsed 5 ms
    2010-11-22 15:13:19.062 Connected: /10.0.1.27:111 (sunrpc), Thread 230, Elapsed 3499 ms
    2010-11-22 15:13:19.109 Connected: /10.0.1.27:139 (netbios-ssn), Thread 278, Elapsed 3532 ms
    2010-11-22 15:13:19.687 Connected: /10.0.1.27:443 (https), Thread 880, Elapsed 3949 ms
    
    2010-11-22 15:13:37.062 Completed.