用bash脚本写一个端口从小到大增加的,ip地址四段随机的ssh连接脚本
时间: 2023-05-29 11:05:04 浏览: 108
Shell脚本实现判断IP地址是否在一个ip段内代码分享
#!/bin/bash
# generate random IP address
ip1=$((RANDOM % 255))
ip2=$((RANDOM % 255))
ip3=$((RANDOM % 255))
ip4=$((RANDOM % 255))
# start with lowest port number
port=22
# loop through ports and attempt SSH connection
while [ $port -lt 65536 ]
do
echo "Trying $ip1.$ip2.$ip3.$ip4:$port..."
ssh -o ConnectTimeout=5 $ip1.$ip2.$ip3.$ip4 -p $port
exit_code=$?
if [ $exit_code -eq 0 ]
then
echo "Connected to $ip1.$ip2.$ip3.$ip4:$port"
break
fi
# increment port number
port=$((port + 1))
done
if [ $exit_code -ne 0 ]
then
echo "Could not connect to $ip1.$ip2.$ip3.$ip4 on any port."
fi
阅读全文