Test connectivity to hosts in file on port 22 with curl command

Multi tool use
Multi tool use

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











up vote
2
down vote

favorite












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



curl -v telnet 10.10.10.10:22


Is this possible?







share|improve this question

























    up vote
    2
    down vote

    favorite












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



    curl -v telnet 10.10.10.10:22


    Is this possible?







    share|improve this question























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











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



      curl -v telnet 10.10.10.10:22


      Is this possible?







      share|improve this question













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



      curl -v telnet 10.10.10.10:22


      Is this possible?









      share|improve this question












      share|improve this question




      share|improve this question








      edited Jun 21 at 18:44









      Tomasz

      8,01552560




      8,01552560









      asked Jun 21 at 18:41









      mylan

      163




      163




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













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



          #!/bin/bash

          host_file=/path/to/file.txt
          out_file=/path/to/out.txt

          while read -r ip; do
          if timeout 5 bash -c "cat < /dev/null >/dev/tcp/$ip/22"; then
          echo -e "$iptSuccess"
          else
          echo -e "$iptFailure"
          fi >> "$out_file"
          done < "$host_file"





          share|improve this answer





















          • I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
            – Tomasz
            Jun 21 at 19:55






          • 1




            @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
            – Jesse_b
            Jun 21 at 20:05

















          up vote
          2
          down vote













          curl is for HTTP / HTTPS / FTP; not for SSH or Telnet.



          I'd just use netcat:



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





          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',
            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%2f451170%2ftest-connectivity-to-hosts-in-file-on-port-22-with-curl-command%23new-answer', 'question_page');

            );

            Post as a guest






























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            2
            down vote













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



            #!/bin/bash

            host_file=/path/to/file.txt
            out_file=/path/to/out.txt

            while read -r ip; do
            if timeout 5 bash -c "cat < /dev/null >/dev/tcp/$ip/22"; then
            echo -e "$iptSuccess"
            else
            echo -e "$iptFailure"
            fi >> "$out_file"
            done < "$host_file"





            share|improve this answer





















            • I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
              – Tomasz
              Jun 21 at 19:55






            • 1




              @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
              – Jesse_b
              Jun 21 at 20:05














            up vote
            2
            down vote













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



            #!/bin/bash

            host_file=/path/to/file.txt
            out_file=/path/to/out.txt

            while read -r ip; do
            if timeout 5 bash -c "cat < /dev/null >/dev/tcp/$ip/22"; then
            echo -e "$iptSuccess"
            else
            echo -e "$iptFailure"
            fi >> "$out_file"
            done < "$host_file"





            share|improve this answer





















            • I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
              – Tomasz
              Jun 21 at 19:55






            • 1




              @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
              – Jesse_b
              Jun 21 at 20:05












            up vote
            2
            down vote










            up vote
            2
            down vote









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



            #!/bin/bash

            host_file=/path/to/file.txt
            out_file=/path/to/out.txt

            while read -r ip; do
            if timeout 5 bash -c "cat < /dev/null >/dev/tcp/$ip/22"; then
            echo -e "$iptSuccess"
            else
            echo -e "$iptFailure"
            fi >> "$out_file"
            done < "$host_file"





            share|improve this answer













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



            #!/bin/bash

            host_file=/path/to/file.txt
            out_file=/path/to/out.txt

            while read -r ip; do
            if timeout 5 bash -c "cat < /dev/null >/dev/tcp/$ip/22"; then
            echo -e "$iptSuccess"
            else
            echo -e "$iptFailure"
            fi >> "$out_file"
            done < "$host_file"






            share|improve this answer













            share|improve this answer



            share|improve this answer











            answered Jun 21 at 19:13









            Jesse_b

            10.2k22658




            10.2k22658











            • I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
              – Tomasz
              Jun 21 at 19:55






            • 1




              @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
              – Jesse_b
              Jun 21 at 20:05
















            • I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
              – Tomasz
              Jun 21 at 19:55






            • 1




              @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
              – Jesse_b
              Jun 21 at 20:05















            I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
            – Tomasz
            Jun 21 at 19:55




            I didn't know this one. Is it documented anywhere? Does it also work with IPv6?
            – Tomasz
            Jun 21 at 19:55




            1




            1




            @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
            – Jesse_b
            Jun 21 at 20:05




            @Tomasz: It's documented in the bash reference manual 3.6 Redirections. I'm unsure if it works with ipv6.
            – Jesse_b
            Jun 21 at 20:05












            up vote
            2
            down vote













            curl is for HTTP / HTTPS / FTP; not for SSH or Telnet.



            I'd just use netcat:



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





            share|improve this answer



























              up vote
              2
              down vote













              curl is for HTTP / HTTPS / FTP; not for SSH or Telnet.



              I'd just use netcat:



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





              share|improve this answer

























                up vote
                2
                down vote










                up vote
                2
                down vote









                curl is for HTTP / HTTPS / FTP; not for SSH or Telnet.



                I'd just use netcat:



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





                share|improve this answer















                curl is for HTTP / HTTPS / FTP; not for SSH or Telnet.



                I'd just use netcat:



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






                share|improve this answer















                share|improve this answer



                share|improve this answer








                edited Jun 21 at 19:26









                Jesse_b

                10.2k22658




                10.2k22658











                answered Jun 21 at 18:49









                DopeGhoti

                39.7k54779




                39.7k54779






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f451170%2ftest-connectivity-to-hosts-in-file-on-port-22-with-curl-command%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    jiYBaM kDBNZXT
                    vVfG,5,elOQKknbDtMPCzUKopL7KzNm 6I I5 WwNi3H,gzp

                    Popular posts from this blog

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

                    How many registers does an x86_64 CPU actually have?

                    Displaying single band from multi-band raster using QGIS