shell script test a telnet connection
up vote
0
down vote
favorite
I'm Trying to make a scipt that checks if my own specific port is open and can be connected.
I tried doing it by netcat by
nc -vz localhost 25565
but this only tells me if the port is open.
I need to check if the port can be connected
I tried by telnet with:
sleep 2 | telnet localhost 25565
This connects to the port and then after 2 seconds got out.
The thing is if there is a way to save if the connection was successfully or not to then make an if or while
command-line bash scripts telnet netcat
add a comment |
up vote
0
down vote
favorite
I'm Trying to make a scipt that checks if my own specific port is open and can be connected.
I tried doing it by netcat by
nc -vz localhost 25565
but this only tells me if the port is open.
I need to check if the port can be connected
I tried by telnet with:
sleep 2 | telnet localhost 25565
This connects to the port and then after 2 seconds got out.
The thing is if there is a way to save if the connection was successfully or not to then make an if or while
command-line bash scripts telnet netcat
I know this can be badly done with save the output string of the connection and then making a comparison
– arthur
Nov 13 at 11:03
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm Trying to make a scipt that checks if my own specific port is open and can be connected.
I tried doing it by netcat by
nc -vz localhost 25565
but this only tells me if the port is open.
I need to check if the port can be connected
I tried by telnet with:
sleep 2 | telnet localhost 25565
This connects to the port and then after 2 seconds got out.
The thing is if there is a way to save if the connection was successfully or not to then make an if or while
command-line bash scripts telnet netcat
I'm Trying to make a scipt that checks if my own specific port is open and can be connected.
I tried doing it by netcat by
nc -vz localhost 25565
but this only tells me if the port is open.
I need to check if the port can be connected
I tried by telnet with:
sleep 2 | telnet localhost 25565
This connects to the port and then after 2 seconds got out.
The thing is if there is a way to save if the connection was successfully or not to then make an if or while
command-line bash scripts telnet netcat
command-line bash scripts telnet netcat
asked Nov 13 at 10:59
arthur
211
211
I know this can be badly done with save the output string of the connection and then making a comparison
– arthur
Nov 13 at 11:03
add a comment |
I know this can be badly done with save the output string of the connection and then making a comparison
– arthur
Nov 13 at 11:03
I know this can be badly done with save the output string of the connection and then making a comparison
– arthur
Nov 13 at 11:03
I know this can be badly done with save the output string of the connection and then making a comparison
– arthur
Nov 13 at 11:03
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
There are a couple of things going on here.
First, an application may be listening on localhost but not on your external adapter, so it is possible you could connect to localhost but others would not be able to. For this reason, in your testing you should use your computer's IP address which is visible to the network rather than localhost. This should be listed in the output of ip addr show
.
To see not only if it is possible to connect to the port, but information about the service running on it, I recommend nmap (replace 192.168...
with your IP):
nmap -A 192.168.0.101 -p 25565
Alternatively, to just confirm that an application is listening on that port:
netstat -tulpn |grep 'b25565b'
Both of these could be included in a while true; do ...; sleep 60; done
script.
+1nmap
is the tool for this.
– Jos
Nov 13 at 11:42
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
There are a couple of things going on here.
First, an application may be listening on localhost but not on your external adapter, so it is possible you could connect to localhost but others would not be able to. For this reason, in your testing you should use your computer's IP address which is visible to the network rather than localhost. This should be listed in the output of ip addr show
.
To see not only if it is possible to connect to the port, but information about the service running on it, I recommend nmap (replace 192.168...
with your IP):
nmap -A 192.168.0.101 -p 25565
Alternatively, to just confirm that an application is listening on that port:
netstat -tulpn |grep 'b25565b'
Both of these could be included in a while true; do ...; sleep 60; done
script.
+1nmap
is the tool for this.
– Jos
Nov 13 at 11:42
add a comment |
up vote
1
down vote
There are a couple of things going on here.
First, an application may be listening on localhost but not on your external adapter, so it is possible you could connect to localhost but others would not be able to. For this reason, in your testing you should use your computer's IP address which is visible to the network rather than localhost. This should be listed in the output of ip addr show
.
To see not only if it is possible to connect to the port, but information about the service running on it, I recommend nmap (replace 192.168...
with your IP):
nmap -A 192.168.0.101 -p 25565
Alternatively, to just confirm that an application is listening on that port:
netstat -tulpn |grep 'b25565b'
Both of these could be included in a while true; do ...; sleep 60; done
script.
+1nmap
is the tool for this.
– Jos
Nov 13 at 11:42
add a comment |
up vote
1
down vote
up vote
1
down vote
There are a couple of things going on here.
First, an application may be listening on localhost but not on your external adapter, so it is possible you could connect to localhost but others would not be able to. For this reason, in your testing you should use your computer's IP address which is visible to the network rather than localhost. This should be listed in the output of ip addr show
.
To see not only if it is possible to connect to the port, but information about the service running on it, I recommend nmap (replace 192.168...
with your IP):
nmap -A 192.168.0.101 -p 25565
Alternatively, to just confirm that an application is listening on that port:
netstat -tulpn |grep 'b25565b'
Both of these could be included in a while true; do ...; sleep 60; done
script.
There are a couple of things going on here.
First, an application may be listening on localhost but not on your external adapter, so it is possible you could connect to localhost but others would not be able to. For this reason, in your testing you should use your computer's IP address which is visible to the network rather than localhost. This should be listed in the output of ip addr show
.
To see not only if it is possible to connect to the port, but information about the service running on it, I recommend nmap (replace 192.168...
with your IP):
nmap -A 192.168.0.101 -p 25565
Alternatively, to just confirm that an application is listening on that port:
netstat -tulpn |grep 'b25565b'
Both of these could be included in a while true; do ...; sleep 60; done
script.
answered Nov 13 at 11:41
bitinerant
212
212
+1nmap
is the tool for this.
– Jos
Nov 13 at 11:42
add a comment |
+1nmap
is the tool for this.
– Jos
Nov 13 at 11:42
+1
nmap
is the tool for this.– Jos
Nov 13 at 11:42
+1
nmap
is the tool for this.– Jos
Nov 13 at 11:42
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1092518%2fshell-script-test-a-telnet-connection%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
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
I know this can be badly done with save the output string of the connection and then making a comparison
– arthur
Nov 13 at 11:03