How to Telnet via BASH Script

This article will show you how to Telnet via BASH script and return the status as open or close. This has been tested on CentOS/RedHat and hopefully should work on all other Linux distributions as well.

Create a file This script is to Telnet SSH port i.e. 22

# vi
echo " 22" | \
while read host port; do
  r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
  if [ "$r" = "0" ]; then
    echo $host $port is open
    echo $host $port is closed


telnet script 1

This is when Telnet for SSH Port responds OK.


telnet script 2

This is when Telnet for SSH Port responds FAIL.

If you encounter any errors during the process, let us know via Contact Us and will try our best to help.

Linux Related Articles . . .

To generate a SHA256 certficate in linux all you need to do is run this openssl command and you will...
This a very useful One liner command to insert IP and hostname into /etc/hosts file and is particularly useful when...
Its possible to use awk in Alias command. I did that by simply just modifying some parenthesis and there you...
Its possible to run a script via Alias command. All you need is to modify the .bashrc and then source...
This article will guide you on creating a custom Self-signed SSL Certificate in no time. For creating one you would...