#!/bin/sh

FILE="${1:-/tmp/do_scan_ftp.sh}"

cat >"$FILE" <<EOF
check_host()
{
	local ip="\$1"
	local nmap_cmd="nmap 2>/dev/null -sT --open -P0 -p 21"

	$nmap_cmd \$ip | grep -q ^'21/tcp open' && {
		logger -s "[OK] \$ip"
	}
}

EOF

for I in $(seq 0 64); do {
	for J in $(seq 0 255); do {
		echo "check_host 10.1.$I.$J &"
	} done
} done >>"$FILE"

logger -s "check '$FILE', or run it directly via:"
logger -s "sh '$FILE'"
