Testing remote TCP port using telnet by running a one-line command

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
8
down vote

favorite
6












I have numerous linux boxes with a very limited set of commands and disk space. But it has the telnet command on it.



I remotely connect to each of these probes (programmatically) and issue one line linux command through SSH.



I need to run a single command to connect to a specific machine, using telnet, and then disconnect right away.



I can do all that, but the disconnection right away part. Telnet opens some sort of a console, or terminal and I can't figure out a one-line command to run the telnet command and then disconnect right away.



If I do that, I can easily parse the textual output for error messages for not being able to connect to the machine on the specified port and that's exactly what I am looking for.



So how can I run a one-line command to connect to a machine using telnet and disconnect afterwards ?










share|improve this question























  • As I understand your Telnet client does not support sending directly?
    – IBr
    Aug 13 '13 at 11:36










  • @IBr, what do you mean ?
    – Muhammad Gelbana
    Aug 13 '13 at 12:14










  • Note that telent clients differ in exit code reported after client side exit command is used to terminate it. So zero exit code should not be considered a signal the port is opened. Does not work for RHEL telent RPM at least.
    – Oliver Gondža
    Jan 6 '17 at 9:59














up vote
8
down vote

favorite
6












I have numerous linux boxes with a very limited set of commands and disk space. But it has the telnet command on it.



I remotely connect to each of these probes (programmatically) and issue one line linux command through SSH.



I need to run a single command to connect to a specific machine, using telnet, and then disconnect right away.



I can do all that, but the disconnection right away part. Telnet opens some sort of a console, or terminal and I can't figure out a one-line command to run the telnet command and then disconnect right away.



If I do that, I can easily parse the textual output for error messages for not being able to connect to the machine on the specified port and that's exactly what I am looking for.



So how can I run a one-line command to connect to a machine using telnet and disconnect afterwards ?










share|improve this question























  • As I understand your Telnet client does not support sending directly?
    – IBr
    Aug 13 '13 at 11:36










  • @IBr, what do you mean ?
    – Muhammad Gelbana
    Aug 13 '13 at 12:14










  • Note that telent clients differ in exit code reported after client side exit command is used to terminate it. So zero exit code should not be considered a signal the port is opened. Does not work for RHEL telent RPM at least.
    – Oliver Gondža
    Jan 6 '17 at 9:59












up vote
8
down vote

favorite
6









up vote
8
down vote

favorite
6






6





I have numerous linux boxes with a very limited set of commands and disk space. But it has the telnet command on it.



I remotely connect to each of these probes (programmatically) and issue one line linux command through SSH.



I need to run a single command to connect to a specific machine, using telnet, and then disconnect right away.



I can do all that, but the disconnection right away part. Telnet opens some sort of a console, or terminal and I can't figure out a one-line command to run the telnet command and then disconnect right away.



If I do that, I can easily parse the textual output for error messages for not being able to connect to the machine on the specified port and that's exactly what I am looking for.



So how can I run a one-line command to connect to a machine using telnet and disconnect afterwards ?










share|improve this question















I have numerous linux boxes with a very limited set of commands and disk space. But it has the telnet command on it.



I remotely connect to each of these probes (programmatically) and issue one line linux command through SSH.



I need to run a single command to connect to a specific machine, using telnet, and then disconnect right away.



I can do all that, but the disconnection right away part. Telnet opens some sort of a console, or terminal and I can't figure out a one-line command to run the telnet command and then disconnect right away.



If I do that, I can easily parse the textual output for error messages for not being able to connect to the machine on the specified port and that's exactly what I am looking for.



So how can I run a one-line command to connect to a machine using telnet and disconnect afterwards ?







bash telnet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 15 at 12:41

























asked Aug 13 '13 at 10:24









Muhammad Gelbana

57051122




57051122











  • As I understand your Telnet client does not support sending directly?
    – IBr
    Aug 13 '13 at 11:36










  • @IBr, what do you mean ?
    – Muhammad Gelbana
    Aug 13 '13 at 12:14










  • Note that telent clients differ in exit code reported after client side exit command is used to terminate it. So zero exit code should not be considered a signal the port is opened. Does not work for RHEL telent RPM at least.
    – Oliver Gondža
    Jan 6 '17 at 9:59
















  • As I understand your Telnet client does not support sending directly?
    – IBr
    Aug 13 '13 at 11:36










  • @IBr, what do you mean ?
    – Muhammad Gelbana
    Aug 13 '13 at 12:14










  • Note that telent clients differ in exit code reported after client side exit command is used to terminate it. So zero exit code should not be considered a signal the port is opened. Does not work for RHEL telent RPM at least.
    – Oliver Gondža
    Jan 6 '17 at 9:59















As I understand your Telnet client does not support sending directly?
– IBr
Aug 13 '13 at 11:36




As I understand your Telnet client does not support sending directly?
– IBr
Aug 13 '13 at 11:36












@IBr, what do you mean ?
– Muhammad Gelbana
Aug 13 '13 at 12:14




@IBr, what do you mean ?
– Muhammad Gelbana
Aug 13 '13 at 12:14












Note that telent clients differ in exit code reported after client side exit command is used to terminate it. So zero exit code should not be considered a signal the port is opened. Does not work for RHEL telent RPM at least.
– Oliver Gondža
Jan 6 '17 at 9:59




Note that telent clients differ in exit code reported after client side exit command is used to terminate it. So zero exit code should not be considered a signal the port is opened. Does not work for RHEL telent RPM at least.
– Oliver Gondža
Jan 6 '17 at 9:59










6 Answers
6






active

oldest

votes

















up vote
18
down vote



accepted










You ought to be able to pipe the exit command into STDIN in telnet.
Try:



echo exit | telnet site port


and see if that works. (it seems to work on my web server, but YMMV).






share|improve this answer





























    up vote
    8
    down vote













    The simplest and easiest method is given below.



     sleep <n> | telnet <server> <port>


    n - The wait time in seconds before auto exit. It could be fractional like 0.5. Note that some required output may not be returned in the specified wait time. So we may need to increase accordingly.



    server - The target server IP or hostname.



    port - Target service port number.



    You can also redirect the output to file like this,



    sleep 1 | telnet <server> <port> > output.log





    share|improve this answer



























      up vote
      3
      down vote













      I think better tool for sending commands directly and just getting output would be netcat. It just simple, but powerful tool for putting commands through ports.
      You could see usage example in this superuser question: https://superuser.com/questions/261900/how-can-i-pipe-commands-to-a-netcat-that-will-stay-alive - asker gives working example in which connection closes after few seconds.



      And if you want just to test connectivity use this:
      http://terminalinflection.com/use-netcat-not-telnet-to-test-network-connectivity/






      share|improve this answer






















      • I'm trying to install netcat right now but I'm unable to do so. I downloaded a compiled powerpc version but glibc library was missing. I downloaded a compiled powerpc version but the device didn't have enough space to copy the library files ! Is it possible that the glibc library already exists but netcat can't find it ?
        – Muhammad Gelbana
        Aug 13 '13 at 12:13










      • Netcat is needed only on client side: on server (probe) can be the same plain old telnet.
        – IBr
        Aug 13 '13 at 13:23











      • Also Glibc should exist already, it is used on much stuff in usual system.
        – IBr
        Aug 13 '13 at 13:28











      • You could try to add to telnet scripts && exit see if it disconnects (in ssh at least it is enough).
        – IBr
        Aug 13 '13 at 13:35










      • && exit didn't work. If glibc should exist and I believe it does. Why would nc.traditional complain about it as if it's missing ?
        – Muhammad Gelbana
        Aug 13 '13 at 14:38

















      up vote
      1
      down vote













      In my case this works. (CentOs7):



      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"
      else
      echo "$host $port is closed"
      exit 1 # To force fail result in ShellScript
      fi
      done


      :) Regards






      share|improve this answer
















      • 1




        Hey, this is great. I am a user on all the Linux systems at my job, but not the admin (and have no admin rights). I'm sick of asking them to install telnet all the time so I can test network connectivity (I'm a network engineer). This is an excellent workaround. I changed it a little to perform more like telnet. I provided my own answer here with the modifications.
        – theglossy1
        Nov 22 '17 at 16:39

















      up vote
      0
      down vote













      This is another version of the answer above that makes it act a little more like "normal" telnet syntax. If you like my answer, please give an upvote not to this, but to the original.



      #!/bin/bash
      if [ "$2" == "" ]; then
      echo "Syntax: $0 <host> <port>"
      exit;
      fi

      host=$1
      port=$2

      r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
      if [ "$r" = "0" ]; then
      echo "$host $port is open"
      else
      echo "$host $port is closed"
      exit 1 # To force fail result in ShellScript
      fi





      share|improve this answer



























        up vote
        0
        down vote













        Here is solution I found on Internet:



        ( echo open 127.0.0.1 23
        sleep 5
        echo your_login
        sleep 5
        echo your_password
        sleep 5
        echo hostname
        sleep 5
        echo exit ) | telnet



        It works for me on SunOS & HP-UX





        share








        New contributor




        Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.

















          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f86556%2ftesting-remote-tcp-port-using-telnet-by-running-a-one-line-command%23new-answer', 'question_page');

          );

          Post as a guest






























          6 Answers
          6






          active

          oldest

          votes








          6 Answers
          6






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          18
          down vote



          accepted










          You ought to be able to pipe the exit command into STDIN in telnet.
          Try:



          echo exit | telnet site port


          and see if that works. (it seems to work on my web server, but YMMV).






          share|improve this answer


























            up vote
            18
            down vote



            accepted










            You ought to be able to pipe the exit command into STDIN in telnet.
            Try:



            echo exit | telnet site port


            and see if that works. (it seems to work on my web server, but YMMV).






            share|improve this answer
























              up vote
              18
              down vote



              accepted







              up vote
              18
              down vote



              accepted






              You ought to be able to pipe the exit command into STDIN in telnet.
              Try:



              echo exit | telnet site port


              and see if that works. (it seems to work on my web server, but YMMV).






              share|improve this answer














              You ought to be able to pipe the exit command into STDIN in telnet.
              Try:



              echo exit | telnet site port


              and see if that works. (it seems to work on my web server, but YMMV).







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Jun 13 '14 at 12:44









              slm♦

              241k66501669




              241k66501669










              answered Aug 13 '13 at 17:11









              Charles Newey

              34615




              34615






















                  up vote
                  8
                  down vote













                  The simplest and easiest method is given below.



                   sleep <n> | telnet <server> <port>


                  n - The wait time in seconds before auto exit. It could be fractional like 0.5. Note that some required output may not be returned in the specified wait time. So we may need to increase accordingly.



                  server - The target server IP or hostname.



                  port - Target service port number.



                  You can also redirect the output to file like this,



                  sleep 1 | telnet <server> <port> > output.log





                  share|improve this answer
























                    up vote
                    8
                    down vote













                    The simplest and easiest method is given below.



                     sleep <n> | telnet <server> <port>


                    n - The wait time in seconds before auto exit. It could be fractional like 0.5. Note that some required output may not be returned in the specified wait time. So we may need to increase accordingly.



                    server - The target server IP or hostname.



                    port - Target service port number.



                    You can also redirect the output to file like this,



                    sleep 1 | telnet <server> <port> > output.log





                    share|improve this answer






















                      up vote
                      8
                      down vote










                      up vote
                      8
                      down vote









                      The simplest and easiest method is given below.



                       sleep <n> | telnet <server> <port>


                      n - The wait time in seconds before auto exit. It could be fractional like 0.5. Note that some required output may not be returned in the specified wait time. So we may need to increase accordingly.



                      server - The target server IP or hostname.



                      port - Target service port number.



                      You can also redirect the output to file like this,



                      sleep 1 | telnet <server> <port> > output.log





                      share|improve this answer












                      The simplest and easiest method is given below.



                       sleep <n> | telnet <server> <port>


                      n - The wait time in seconds before auto exit. It could be fractional like 0.5. Note that some required output may not be returned in the specified wait time. So we may need to increase accordingly.



                      server - The target server IP or hostname.



                      port - Target service port number.



                      You can also redirect the output to file like this,



                      sleep 1 | telnet <server> <port> > output.log






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jun 13 '14 at 12:18









                      Seff

                      21024




                      21024




















                          up vote
                          3
                          down vote













                          I think better tool for sending commands directly and just getting output would be netcat. It just simple, but powerful tool for putting commands through ports.
                          You could see usage example in this superuser question: https://superuser.com/questions/261900/how-can-i-pipe-commands-to-a-netcat-that-will-stay-alive - asker gives working example in which connection closes after few seconds.



                          And if you want just to test connectivity use this:
                          http://terminalinflection.com/use-netcat-not-telnet-to-test-network-connectivity/






                          share|improve this answer






















                          • I'm trying to install netcat right now but I'm unable to do so. I downloaded a compiled powerpc version but glibc library was missing. I downloaded a compiled powerpc version but the device didn't have enough space to copy the library files ! Is it possible that the glibc library already exists but netcat can't find it ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 12:13










                          • Netcat is needed only on client side: on server (probe) can be the same plain old telnet.
                            – IBr
                            Aug 13 '13 at 13:23











                          • Also Glibc should exist already, it is used on much stuff in usual system.
                            – IBr
                            Aug 13 '13 at 13:28











                          • You could try to add to telnet scripts && exit see if it disconnects (in ssh at least it is enough).
                            – IBr
                            Aug 13 '13 at 13:35










                          • && exit didn't work. If glibc should exist and I believe it does. Why would nc.traditional complain about it as if it's missing ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 14:38














                          up vote
                          3
                          down vote













                          I think better tool for sending commands directly and just getting output would be netcat. It just simple, but powerful tool for putting commands through ports.
                          You could see usage example in this superuser question: https://superuser.com/questions/261900/how-can-i-pipe-commands-to-a-netcat-that-will-stay-alive - asker gives working example in which connection closes after few seconds.



                          And if you want just to test connectivity use this:
                          http://terminalinflection.com/use-netcat-not-telnet-to-test-network-connectivity/






                          share|improve this answer






















                          • I'm trying to install netcat right now but I'm unable to do so. I downloaded a compiled powerpc version but glibc library was missing. I downloaded a compiled powerpc version but the device didn't have enough space to copy the library files ! Is it possible that the glibc library already exists but netcat can't find it ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 12:13










                          • Netcat is needed only on client side: on server (probe) can be the same plain old telnet.
                            – IBr
                            Aug 13 '13 at 13:23











                          • Also Glibc should exist already, it is used on much stuff in usual system.
                            – IBr
                            Aug 13 '13 at 13:28











                          • You could try to add to telnet scripts && exit see if it disconnects (in ssh at least it is enough).
                            – IBr
                            Aug 13 '13 at 13:35










                          • && exit didn't work. If glibc should exist and I believe it does. Why would nc.traditional complain about it as if it's missing ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 14:38












                          up vote
                          3
                          down vote










                          up vote
                          3
                          down vote









                          I think better tool for sending commands directly and just getting output would be netcat. It just simple, but powerful tool for putting commands through ports.
                          You could see usage example in this superuser question: https://superuser.com/questions/261900/how-can-i-pipe-commands-to-a-netcat-that-will-stay-alive - asker gives working example in which connection closes after few seconds.



                          And if you want just to test connectivity use this:
                          http://terminalinflection.com/use-netcat-not-telnet-to-test-network-connectivity/






                          share|improve this answer














                          I think better tool for sending commands directly and just getting output would be netcat. It just simple, but powerful tool for putting commands through ports.
                          You could see usage example in this superuser question: https://superuser.com/questions/261900/how-can-i-pipe-commands-to-a-netcat-that-will-stay-alive - asker gives working example in which connection closes after few seconds.



                          And if you want just to test connectivity use this:
                          http://terminalinflection.com/use-netcat-not-telnet-to-test-network-connectivity/







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 20 '17 at 10:18









                          Community♦

                          1




                          1










                          answered Aug 13 '13 at 11:41









                          IBr

                          1,1751923




                          1,1751923











                          • I'm trying to install netcat right now but I'm unable to do so. I downloaded a compiled powerpc version but glibc library was missing. I downloaded a compiled powerpc version but the device didn't have enough space to copy the library files ! Is it possible that the glibc library already exists but netcat can't find it ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 12:13










                          • Netcat is needed only on client side: on server (probe) can be the same plain old telnet.
                            – IBr
                            Aug 13 '13 at 13:23











                          • Also Glibc should exist already, it is used on much stuff in usual system.
                            – IBr
                            Aug 13 '13 at 13:28











                          • You could try to add to telnet scripts && exit see if it disconnects (in ssh at least it is enough).
                            – IBr
                            Aug 13 '13 at 13:35










                          • && exit didn't work. If glibc should exist and I believe it does. Why would nc.traditional complain about it as if it's missing ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 14:38
















                          • I'm trying to install netcat right now but I'm unable to do so. I downloaded a compiled powerpc version but glibc library was missing. I downloaded a compiled powerpc version but the device didn't have enough space to copy the library files ! Is it possible that the glibc library already exists but netcat can't find it ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 12:13










                          • Netcat is needed only on client side: on server (probe) can be the same plain old telnet.
                            – IBr
                            Aug 13 '13 at 13:23











                          • Also Glibc should exist already, it is used on much stuff in usual system.
                            – IBr
                            Aug 13 '13 at 13:28











                          • You could try to add to telnet scripts && exit see if it disconnects (in ssh at least it is enough).
                            – IBr
                            Aug 13 '13 at 13:35










                          • && exit didn't work. If glibc should exist and I believe it does. Why would nc.traditional complain about it as if it's missing ?
                            – Muhammad Gelbana
                            Aug 13 '13 at 14:38















                          I'm trying to install netcat right now but I'm unable to do so. I downloaded a compiled powerpc version but glibc library was missing. I downloaded a compiled powerpc version but the device didn't have enough space to copy the library files ! Is it possible that the glibc library already exists but netcat can't find it ?
                          – Muhammad Gelbana
                          Aug 13 '13 at 12:13




                          I'm trying to install netcat right now but I'm unable to do so. I downloaded a compiled powerpc version but glibc library was missing. I downloaded a compiled powerpc version but the device didn't have enough space to copy the library files ! Is it possible that the glibc library already exists but netcat can't find it ?
                          – Muhammad Gelbana
                          Aug 13 '13 at 12:13












                          Netcat is needed only on client side: on server (probe) can be the same plain old telnet.
                          – IBr
                          Aug 13 '13 at 13:23





                          Netcat is needed only on client side: on server (probe) can be the same plain old telnet.
                          – IBr
                          Aug 13 '13 at 13:23













                          Also Glibc should exist already, it is used on much stuff in usual system.
                          – IBr
                          Aug 13 '13 at 13:28





                          Also Glibc should exist already, it is used on much stuff in usual system.
                          – IBr
                          Aug 13 '13 at 13:28













                          You could try to add to telnet scripts && exit see if it disconnects (in ssh at least it is enough).
                          – IBr
                          Aug 13 '13 at 13:35




                          You could try to add to telnet scripts && exit see if it disconnects (in ssh at least it is enough).
                          – IBr
                          Aug 13 '13 at 13:35












                          && exit didn't work. If glibc should exist and I believe it does. Why would nc.traditional complain about it as if it's missing ?
                          – Muhammad Gelbana
                          Aug 13 '13 at 14:38




                          && exit didn't work. If glibc should exist and I believe it does. Why would nc.traditional complain about it as if it's missing ?
                          – Muhammad Gelbana
                          Aug 13 '13 at 14:38










                          up vote
                          1
                          down vote













                          In my case this works. (CentOs7):



                          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"
                          else
                          echo "$host $port is closed"
                          exit 1 # To force fail result in ShellScript
                          fi
                          done


                          :) Regards






                          share|improve this answer
















                          • 1




                            Hey, this is great. I am a user on all the Linux systems at my job, but not the admin (and have no admin rights). I'm sick of asking them to install telnet all the time so I can test network connectivity (I'm a network engineer). This is an excellent workaround. I changed it a little to perform more like telnet. I provided my own answer here with the modifications.
                            – theglossy1
                            Nov 22 '17 at 16:39














                          up vote
                          1
                          down vote













                          In my case this works. (CentOs7):



                          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"
                          else
                          echo "$host $port is closed"
                          exit 1 # To force fail result in ShellScript
                          fi
                          done


                          :) Regards






                          share|improve this answer
















                          • 1




                            Hey, this is great. I am a user on all the Linux systems at my job, but not the admin (and have no admin rights). I'm sick of asking them to install telnet all the time so I can test network connectivity (I'm a network engineer). This is an excellent workaround. I changed it a little to perform more like telnet. I provided my own answer here with the modifications.
                            – theglossy1
                            Nov 22 '17 at 16:39












                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          In my case this works. (CentOs7):



                          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"
                          else
                          echo "$host $port is closed"
                          exit 1 # To force fail result in ShellScript
                          fi
                          done


                          :) Regards






                          share|improve this answer












                          In my case this works. (CentOs7):



                          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"
                          else
                          echo "$host $port is closed"
                          exit 1 # To force fail result in ShellScript
                          fi
                          done


                          :) Regards







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 23 '17 at 21:34









                          Chuss

                          211




                          211







                          • 1




                            Hey, this is great. I am a user on all the Linux systems at my job, but not the admin (and have no admin rights). I'm sick of asking them to install telnet all the time so I can test network connectivity (I'm a network engineer). This is an excellent workaround. I changed it a little to perform more like telnet. I provided my own answer here with the modifications.
                            – theglossy1
                            Nov 22 '17 at 16:39












                          • 1




                            Hey, this is great. I am a user on all the Linux systems at my job, but not the admin (and have no admin rights). I'm sick of asking them to install telnet all the time so I can test network connectivity (I'm a network engineer). This is an excellent workaround. I changed it a little to perform more like telnet. I provided my own answer here with the modifications.
                            – theglossy1
                            Nov 22 '17 at 16:39







                          1




                          1




                          Hey, this is great. I am a user on all the Linux systems at my job, but not the admin (and have no admin rights). I'm sick of asking them to install telnet all the time so I can test network connectivity (I'm a network engineer). This is an excellent workaround. I changed it a little to perform more like telnet. I provided my own answer here with the modifications.
                          – theglossy1
                          Nov 22 '17 at 16:39




                          Hey, this is great. I am a user on all the Linux systems at my job, but not the admin (and have no admin rights). I'm sick of asking them to install telnet all the time so I can test network connectivity (I'm a network engineer). This is an excellent workaround. I changed it a little to perform more like telnet. I provided my own answer here with the modifications.
                          – theglossy1
                          Nov 22 '17 at 16:39










                          up vote
                          0
                          down vote













                          This is another version of the answer above that makes it act a little more like "normal" telnet syntax. If you like my answer, please give an upvote not to this, but to the original.



                          #!/bin/bash
                          if [ "$2" == "" ]; then
                          echo "Syntax: $0 <host> <port>"
                          exit;
                          fi

                          host=$1
                          port=$2

                          r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
                          if [ "$r" = "0" ]; then
                          echo "$host $port is open"
                          else
                          echo "$host $port is closed"
                          exit 1 # To force fail result in ShellScript
                          fi





                          share|improve this answer
























                            up vote
                            0
                            down vote













                            This is another version of the answer above that makes it act a little more like "normal" telnet syntax. If you like my answer, please give an upvote not to this, but to the original.



                            #!/bin/bash
                            if [ "$2" == "" ]; then
                            echo "Syntax: $0 <host> <port>"
                            exit;
                            fi

                            host=$1
                            port=$2

                            r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
                            if [ "$r" = "0" ]; then
                            echo "$host $port is open"
                            else
                            echo "$host $port is closed"
                            exit 1 # To force fail result in ShellScript
                            fi





                            share|improve this answer






















                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              This is another version of the answer above that makes it act a little more like "normal" telnet syntax. If you like my answer, please give an upvote not to this, but to the original.



                              #!/bin/bash
                              if [ "$2" == "" ]; then
                              echo "Syntax: $0 <host> <port>"
                              exit;
                              fi

                              host=$1
                              port=$2

                              r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
                              if [ "$r" = "0" ]; then
                              echo "$host $port is open"
                              else
                              echo "$host $port is closed"
                              exit 1 # To force fail result in ShellScript
                              fi





                              share|improve this answer












                              This is another version of the answer above that makes it act a little more like "normal" telnet syntax. If you like my answer, please give an upvote not to this, but to the original.



                              #!/bin/bash
                              if [ "$2" == "" ]; then
                              echo "Syntax: $0 <host> <port>"
                              exit;
                              fi

                              host=$1
                              port=$2

                              r=$(bash -c 'exec 3<> /dev/tcp/'$host'/'$port';echo $?' 2>/dev/null)
                              if [ "$r" = "0" ]; then
                              echo "$host $port is open"
                              else
                              echo "$host $port is closed"
                              exit 1 # To force fail result in ShellScript
                              fi






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Nov 22 '17 at 16:42









                              theglossy1

                              1012




                              1012




















                                  up vote
                                  0
                                  down vote













                                  Here is solution I found on Internet:



                                  ( echo open 127.0.0.1 23
                                  sleep 5
                                  echo your_login
                                  sleep 5
                                  echo your_password
                                  sleep 5
                                  echo hostname
                                  sleep 5
                                  echo exit ) | telnet



                                  It works for me on SunOS & HP-UX





                                  share








                                  New contributor




                                  Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                  Check out our Code of Conduct.





















                                    up vote
                                    0
                                    down vote













                                    Here is solution I found on Internet:



                                    ( echo open 127.0.0.1 23
                                    sleep 5
                                    echo your_login
                                    sleep 5
                                    echo your_password
                                    sleep 5
                                    echo hostname
                                    sleep 5
                                    echo exit ) | telnet



                                    It works for me on SunOS & HP-UX





                                    share








                                    New contributor




                                    Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                    Check out our Code of Conduct.



















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      Here is solution I found on Internet:



                                      ( echo open 127.0.0.1 23
                                      sleep 5
                                      echo your_login
                                      sleep 5
                                      echo your_password
                                      sleep 5
                                      echo hostname
                                      sleep 5
                                      echo exit ) | telnet



                                      It works for me on SunOS & HP-UX





                                      share








                                      New contributor




                                      Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      Here is solution I found on Internet:



                                      ( echo open 127.0.0.1 23
                                      sleep 5
                                      echo your_login
                                      sleep 5
                                      echo your_password
                                      sleep 5
                                      echo hostname
                                      sleep 5
                                      echo exit ) | telnet



                                      It works for me on SunOS & HP-UX






                                      share








                                      New contributor




                                      Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.








                                      share


                                      share






                                      New contributor




                                      Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.









                                      answered 2 mins ago









                                      Vladimir

                                      1




                                      1




                                      New contributor




                                      Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.





                                      New contributor





                                      Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.






                                      Vladimir is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                                      Check out our Code of Conduct.



























                                           

                                          draft saved


                                          draft discarded















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f86556%2ftesting-remote-tcp-port-using-telnet-by-running-a-one-line-command%23new-answer', 'question_page');

                                          );

                                          Post as a guest













































































                                          Popular posts from this blog

                                          How to check contact read email or not when send email to Individual?

                                          Bahrain

                                          Postfix configuration issue with fips on centos 7; mailgun relay