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










share|improve this question






















  • 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

















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










share|improve this question






















  • 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















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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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




















  • 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












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.






share|improve this answer





















  • +1 nmap is the tool for this.
    – Jos
    Nov 13 at 11:42











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f1092518%2fshell-script-test-a-telnet-connection%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























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.






share|improve this answer





















  • +1 nmap is the tool for this.
    – Jos
    Nov 13 at 11:42















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.






share|improve this answer





















  • +1 nmap is the tool for this.
    – Jos
    Nov 13 at 11:42













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 at 11:41









bitinerant

212




212












  • +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
















+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


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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





















































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

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?