shell脚本实现批量端口扫描

#!/bin/bash
# Telnet Batach
readonly TMOUT=3

ip_prefix="192.168"
ip_network_range="80-80"
ip_network_host_range="1-254"
port_range="445-445"
ports="135 445 3389 3306"
execute_num=3000


function telnet_batch()
{
  ip="$1"
  port="$2"
  script_ping='echo ""|telnet '$ip' '$port' 2> /dev/null|grep "Escape character is"&>/dev/null;[[ $? -eq 0 ]] && echo -e "\033[32m'$ip' '$port' yes\033[0m" || echo -e "\033[36m'$ip' '$port' no\033[0m">/dev/null'
  eval $script_ping &
}
function sleep_wait()
{
  sleep 2
  [[ $(ps -ef|wc -l) -ge $execute_num ]] && sleep_wait;
}

for port in $ports;do for i in `seq $(echo $ip_network_range|awk -F '-' '{print $1}') $(echo $ip_network_range|awk -F '-' '{print $2}')`;do [[ $(ps -ef|wc -l) -ge $execute_num ]] && sleep_wait;for j in `seq $(echo $ip_network_host_range|awk -F '-' '{print $1}') $(echo $ip_network_host_range|awk -F '-' '{print $2}')`;do telnet_batch "${ip_prefix}.${i}.${j}" "$port";done;done;done

 

转载于:https://www.cnblogs.com/tianyuanchen/p/11375104.html

你可能感兴趣的:(shell脚本实现批量端口扫描)