我需要做一个 IP 多线程扫描器,但我没有得到它,我需要“seq”来与多线程
#!/bin/bash一起工作
function teste(){
for i in $(seq 0 10); do
CONNECT_TIMEOUT=1 # in seconds
A="$1."
B=$i
IP_ADDRESS=$A$B
PORT="${2}"
set +e
data=$(curl --head -vs -m ${CONNECT_TIMEOUT} http://${IP_ADDRESS}:${PORT} 2>&1)
exit_code="$?"
data=$(echo -ne "${data}" | grep "Server: ")
set -e
if [[ ${exit_code} -eq 0 ]]; then
if [[ -n "${data}" ]]; then
echo -ne "${IP_ADDRESS} - ${data}"
else
echo "${IP_ADDRESS} - Got empty data for server!"
fi
else
echo "${IP_ADDRESS} - no server."
fi
done
}
set -e
if [[ $# -ne 2 ]]; then
echo "Usage: $(basename "$0") ip_address_number port"
exit 1
fi
threads=10;
threads=$(( $threads - 1))
for thread in `seq $threads`
do
teste ${1} &
done
答案1
也许你可以考虑使用命令parallel
来解决这个问题。示例如下
funcOperation(){
# operation procedure
}
export -f funcOperation
cat ip_port.list | parallel -k -j 0 funcOperation
你也可以使用seq
,这里我就不放代码示例了。