#!/bin/bash
########17615148328#######
input_file="ip.txt"
output_file="output.txt"
if [ ! -f "$input_file" ]; then
echo "Error: Input file '$input_file' not found."
exit 1
fi
read -p "请输入你要查询的端口类型(TCP/UDP):" edd
read -p "请输入你要查询的端口号:" wsn
# 遍历文件中的每个IP地址进行测试
while IFS= read -r host; do
if [ "$edd" == "TCP" ]; then
nc -z -w 3 "$host" "$wsn"
elif [ "$edd" == "UDP" ]; then
nc -uz -w 3 "$host" "$wsn"
else
echo "错误:未知的端口类型,请输入TCP或UDP。"
exit 1
fi
# 检查 nc 命令的返回值,如果不为 0 则端口不通
if [ $? -eq 0 ]; then
echo "端口 $port on $host is OPEN"
else
echo "端口 $port on $host is CLOSED"
fi
done < "$input_file"
使用方法:在当前目录下创建 一个ip.txt文件ip.txt 放入你要检测的ip,
No Comments