Test connectivity to hosts in file on port 22 with curl command
Clash 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?
shell-script ssh curl
add a comment |Â
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?
shell-script ssh curl
add a comment |Â
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?
shell-script ssh curl
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?
shell-script ssh curl
edited Jun 21 at 18:44
Tomasz
8,01552560
8,01552560
asked Jun 21 at 18:41
mylan
163
163
add a comment |Â
add a comment |Â
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"
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
add a comment |Â
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
add a comment |Â
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"
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
add a comment |Â
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"
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
add a comment |Â
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"
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"
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
edited Jun 21 at 19:26
Jesse_b
10.2k22658
10.2k22658
answered Jun 21 at 18:49
DopeGhoti
39.7k54779
39.7k54779
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password