可以将以下脚本保存到sh文件中:test.sh:
#!/bin/bash IP=$1 first_port=$2 last_port=$3 function scanner { for ((port=$first_port; port<=$last_port; port++)); do (echo >/dev/tcp/$IP/$port)> /dev/null 2>&1 && echo $port open || echo "$port closed" done } scanner
然后执行命令:
sh test.sh 10.195.67.33 6000 10000 > scan.result
执行完后scan.result中,*** open表示端口已被占用;*** close表示未被占用