Ben Stienstra

Linux, Unix, network, radio and more...

User Tools

Site Tools


bash_portscan_banners

~~TOC~~

Pure bash TCP portscan and bannergrabber

Sequential portscan

#!/bin/bash

IP=1.2.3.4

for port in {1..1023}
do
	echo -n "${IP} port ${port} - "
	timeout 1s bash -c "</dev/tcp/${IP}/${port}" 2>/dev/null && echo open || echo closed
done

Parallel portscan

Test 10 ports in parallel.

#!/bin/bash

PAR=10
IP=127.0.0.1

(
for port in {1..1000}
do
	((i=i%PAR)); ((i++==0)) && wait
	timeout 1s bash -c "</dev/tcp/${IP}/${port}" 2>/dev/null && echo ${port} open || echo ${port} closed &
done
)

Bannergrab

#!/bin/bash

IP=1.2.3.4

for i in {1..1000}
do
	echo -n "${IP} port ${i} - "
	timeout 1s bash -c "head -1 </dev/tcp/${IP}/${i}" 2>/dev/null || echo closed
done
bash_portscan_banners.txt · Last modified: 2017/08/31 08:37 by admin