我如何减少连接时 unix telnet 上的超时 [英] how do i reduce timeout on unix telnet on connection
本文介绍了我如何减少连接时 unix telnet 上的超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 unix shell 脚本,用于测试文件中列出的多个主机的 ftp 端口.
I have a unix shell script which test ftp ports of multiple hosts listed in a file.
for i in `cat ftp-hosts.txt`
do
echo "QUIT" | telnet $i 21
done
一般来说,这个脚本可以工作,但是如果我遇到一个无法连接的主机,即 telnet 正在尝试...",我该如何减少等待时间以便它可以测试下一个主机?
In general this scripts works, however if i encounter a host which does not connect, i.e telnet is "Trying...", how can I reduce this wait time so it can test the next host ?
推荐答案
您是否尝试过使用 netcat (nc
) 而不是 telnet?它具有更大的灵活性,包括能够设置超时:
Have you tried using netcat (nc
) instead of telnet? It has more flexibility, including being able to set the timeout:
echo 'QUIT' | nc -w SECONDS YOUR_HOST PORT
# e.g.
echo "QUIT" | nc -w 5 localhost 21
-w 5
选项将在 5 秒后超时连接.
The -w 5
option will timeout the connection after 5 seconds.
这篇关于我如何减少连接时 unix telnet 上的超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文