Testing remote TCP port using telnet by running a one-line commandHow can I use command line telnet client to...

How can I grammatically understand "Wir über uns"?

What does it mean by "d-ism of Leibniz" and "dotage of Newton" in simple English?

How can I determine the spell save DC of a monster/NPC?

Is there a rule that prohibits us from using 2 possessives in a row?

Computing the differentials in the Adams spectral sequence

What does War Machine's "Canopy! Canopy!" line mean in "Avengers: Endgame"?

Applicants clearly not having the skills they advertise

Will dual-learning in a glider make my airplane learning safer?

What people are called boars ("кабан") and why?

Why does MS SQL allow you to create an illegal column?

Is there a term for this?

Does any lore text explain why the planes of Acheron, Gehenna, and Carceri are the alignment they are?

Responsibility for visa checking

What is the right way to float a home lab?

What's the most polite way to tell a manager "shut up and let me work"?

Is it possible for people to live in the eye of a permanent hypercane?

Why is Colorado so different politically from nearby states?

Why was it possible to cause an Apple //e to shut down with SHIFT and paddle button 2?

Could a guilty Boris Johnson be used to cancel Brexit?

Strange math syntax in old basic listing

You've spoiled/damaged the card

How is it possible for this NPC to be alive during the Curse of Strahd adventure?

Sucuri detects malware on wordpress but I can't find the malicious code

What is a simple, physical situation where complex numbers emerge naturally?



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


How can I use command line telnet client to open a raw connection - like PuTTY?start apache scriptKali Linux shows strange line of code using Bash command “set”Correctly parse arguments in script behaving like a shell called through SSHUsing process substitution to trick programs expecting files, with specific extensions as argument?How to block telnet using iptables commandhow to see a http reponse message using telnet command?Testing remote host connectivity using telnetinteractive SMTP command using telnet via a shell scriptSecurely Piping String in Local Text File to Remote Command using SSH






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







10















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


















10















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














10












10








10


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 '18 at 12:41







Muhammad Gelbana

















asked Aug 13 '13 at 10:24









Muhammad GelbanaMuhammad Gelbana

61561223




61561223













  • 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


















24














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


























  • might work but seems dumb - telnet should have an option to exit or something on first contact

    – Alexander Mills
    1 hour ago



















9














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
























  • This works perfectly! While the output is indeed redirected, I noticed I still get the "Connection closed by foreign host." output in my console after the sleep rather than in the output.log file. Any way to prevent this?

    – dnLL
    Apr 3 at 18:43



















3














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



















1














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



















1














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































    0














    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|improve this answer
























      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',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      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















      Required, but never shown

























      6 Answers
      6






      active

      oldest

      votes








      6 Answers
      6






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      24














      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


























      • might work but seems dumb - telnet should have an option to exit or something on first contact

        – Alexander Mills
        1 hour ago
















      24














      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


























      • might work but seems dumb - telnet should have an option to exit or something on first contact

        – Alexander Mills
        1 hour ago














      24












      24








      24







      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 1 hour ago









      Alexander Mills

      2,39721962




      2,39721962










      answered Aug 13 '13 at 17:11









      Charles NeweyCharles Newey

      40625




      40625













      • might work but seems dumb - telnet should have an option to exit or something on first contact

        – Alexander Mills
        1 hour ago



















      • might work but seems dumb - telnet should have an option to exit or something on first contact

        – Alexander Mills
        1 hour ago

















      might work but seems dumb - telnet should have an option to exit or something on first contact

      – Alexander Mills
      1 hour ago





      might work but seems dumb - telnet should have an option to exit or something on first contact

      – Alexander Mills
      1 hour ago













      9














      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
























      • This works perfectly! While the output is indeed redirected, I noticed I still get the "Connection closed by foreign host." output in my console after the sleep rather than in the output.log file. Any way to prevent this?

        – dnLL
        Apr 3 at 18:43
















      9














      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
























      • This works perfectly! While the output is indeed redirected, I noticed I still get the "Connection closed by foreign host." output in my console after the sleep rather than in the output.log file. Any way to prevent this?

        – dnLL
        Apr 3 at 18:43














      9












      9








      9







      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









      SeffSeff

      23024




      23024













      • This works perfectly! While the output is indeed redirected, I noticed I still get the "Connection closed by foreign host." output in my console after the sleep rather than in the output.log file. Any way to prevent this?

        – dnLL
        Apr 3 at 18:43



















      • This works perfectly! While the output is indeed redirected, I noticed I still get the "Connection closed by foreign host." output in my console after the sleep rather than in the output.log file. Any way to prevent this?

        – dnLL
        Apr 3 at 18:43

















      This works perfectly! While the output is indeed redirected, I noticed I still get the "Connection closed by foreign host." output in my console after the sleep rather than in the output.log file. Any way to prevent this?

      – dnLL
      Apr 3 at 18:43





      This works perfectly! While the output is indeed redirected, I noticed I still get the "Connection closed by foreign host." output in my console after the sleep rather than in the output.log file. Any way to prevent this?

      – dnLL
      Apr 3 at 18:43











      3














      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
















      3














      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














      3












      3








      3







      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









      IBrIBr

      1,26031124




      1,26031124













      • 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











      1














      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
















      1














      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














      1












      1








      1







      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









      ChussChuss

      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











      1














      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




























        1














        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


























          1












          1








          1







          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









          theglossy1theglossy1

          1113




          1113























              0














              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|improve this answer




























                0














                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|improve this answer


























                  0












                  0








                  0







                  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|improve this answer













                  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|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 24 '18 at 21:05









                  VladimirVladimir

                  1




                  1






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Unix & Linux Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      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















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

                      Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

                      Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m