#!/bin/bash read -p "请输入要检测的IP地址:" target_ip read -p "请输入检测的起始端口:" start_port read -p "请输入检测的结束端口:" end_port echo "开始扫描 $target_ip" for ((port=$start_port; port<=$end_port; port++)) do (echo >/dev/tcp/$target_ip/$port) >/dev/null 2>&1 && echo "端口 $port 已开放" done