Id like to plug the following "curl" command into a bash script and run it against a hostfile of ip addresses then display the output as success or failure in an output file.

curl -v telnet

Is this possible?

3 Answers 3


I don't yet have the reputation necessary to comment on the post that claims curl isn't for ssh or telnet. That is not accurate. Curl handles a multitude of protocols, including telnet, ssh, scp, sftp, ftps, and more.

This is the correct syntax for curl:

curl -v telnet://

Using the bash builtin to check for open ports may work as well:



while read -r ip; do
    if timeout 5 bash -c "cat < /dev/null >/dev/tcp/${ip}/22"; then
        echo -e "${ip}\tSuccess"
        echo -e "${ip}\tFailure" 
    fi >> "$out_file"
done < "$host_file"
  • I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
    – user147505
    Commented Jun 21, 2018 at 19:55
  • 1
    @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
    – jesse_b
    Commented Jun 21, 2018 at 20:05

curl is generally used for HTTP / HTTPS / FTP; not so much for SSH or Telnet.

I'd just use netcat:

testport=22 # 22 for ssh; 23 for telnet; 80 for HTTP; etc.
while read ip; do
    if nc -w2 -z $ip $testport; then
        echo $ip up
        echo $ip down
    fi >> testresults.txt
done < hostlist.txt

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .