port scanner
Java TCP Port Scanner
I found the source code for a TCP(IPv4) port scanner. Originally, it was written for Java 1.4 (according to the CVS history), but I found an update for Java 1.6 which connects to the found port and prints the header.
I searched for it because I needed a port scanner. On Linux, I am not allowed to install nmap, and the same restriction applies on Windows due to corporate rules.
So here it is: pscan
Usage
The best way to use it is to modify pscan.sh
.
To ensure you find all open TCP ports, use very conservative numbers
Java Properties description(pscan.sh
):
- -Dportscanner.autotune=true
- If set to true, the following
autotune
values will be used. If set to false, you can specify the the values on the command line(else a default wt=500 and fd=128 is used)
- If set to true, the following
- -Dportscanner.tcp.autotune.same.fd=2048
- number of file descriptors to use
- -Dportscanner.tcp.autotune.same.wt=30
- if on the same subnet, time in ms to wait for the packet to arrive
- -Dportscanner.tcp.autotune.notsame.fd=512
- -Dportscanner.tcp.autotune.notsame.wt=512
- if not on same subnet
- -Dportscanner.tcp.connectscan=true
- If set to true, it will use the following values, establish a real connection, and attempt to read the
sockbuf
bytes for banner printing.
- If set to true, it will use the following values, establish a real connection, and attempt to read the
- -Dportscanner.tcp.connectscan.threads=16
- Number of threads in the pool used for the connect scan
- -Dportscanner.tcp.sockbuf=1024
- read number of byte from input stream
- -Dportscanner.tcp.readtimeout=1900
- wait max 1900 ms on read call
- -Dportscanner.tcp.connectdelay=100
- delay in ms to wait in connect thread before real connect is issued.
- -Dportscanner.loglevel=1
- max: 5 super verbose. 2 should be enough
Examples
loglevel=0 and autotune=true:
./pscan.sh localhost 1 65535
###### List of open ports ######
################################
open <localhost/127.0.0.1:139 -> >
open <localhost/127.0.0.1:445 -> >
open <localhost/127.0.0.1:631 -> >
open <localhost/127.0.0.1:1716 -> >
open <localhost/127.0.0.1:11233 -> TEST
>
open <localhost/127.0.0.1:11434 -> >
open <localhost/127.0.0.1:37753 -> >
open <localhost/127.0.0.1:43881 -> >
open <localhost/127.0.0.1:58978 -> >
open <localhost/127.0.0.1:64120 -> >
open <localhost/127.0.0.1:64121 -> >
5 s to find 11 open ports from 65534
loglevel=1 and autotune=false:
./pscan.sh fritz.box 1 65535 50 192
fritz.box/192.168.0.1:53 found. Checking connect/banner string
fritz.box/192.168.0.1:80 found. Checking connect/banner string
fritz.box/192.168.0.1:139 found. Checking connect/banner string
fritz.box/192.168.0.1:443 found. Checking connect/banner string
fritz.box/192.168.0.1:445 found. Checking connect/banner string
fritz.box/192.168.0.1:5060 found. Checking connect/banner string
fritz.box/192.168.0.1:5357 found. Checking connect/banner string
fritz.box/192.168.0.1:8181 found. Checking connect/banner string
fritz.box/192.168.0.1:8182 found. Checking connect/banner string
fritz.box/192.168.0.1:8183 found. Checking connect/banner string
fritz.box/192.168.0.1:8184 found. Checking connect/banner string
fritz.box/192.168.0.1:8185 found. Checking connect/banner string
fritz.box/192.168.0.1:8186 found. Checking connect/banner string
fritz.box/192.168.0.1:46063 found. Checking connect/banner string
fritz.box/192.168.0.1:49000 found. Checking connect/banner string
fritz.box/192.168.0.1:49443 found. Checking connect/banner string
fritz.box/192.168.0.1:56425 found. Checking connect/banner string
###### List of open ports ######
################################
open <fritz.box/192.168.0.1:53 -> >
open <fritz.box/192.168.0.1:80 -> >
open <fritz.box/192.168.0.1:139 -> >
open <fritz.box/192.168.0.1:443 -> >
open <fritz.box/192.168.0.1:445 -> >
open <fritz.box/192.168.0.1:5060 -> >
open <fritz.box/192.168.0.1:5357 -> >
open <fritz.box/192.168.0.1:8181 -> >
open <fritz.box/192.168.0.1:8182 -> >
open <fritz.box/192.168.0.1:8183 -> >
open <fritz.box/192.168.0.1:8184 -> >
open <fritz.box/192.168.0.1:8185 -> >
open <fritz.box/192.168.0.1:8186 -> >
open <fritz.box/192.168.0.1:46063 -> >
open <fritz.box/192.168.0.1:49000 -> >
open <fritz.box/192.168.0.1:49443 -> >
open <fritz.box/192.168.0.1:56425 -> >
33 s to find 17 open ports from 65534