How can I use the telnet program to check whether the specified tcp port is available on the specified machine, and does any program listen to this port?


canonical answers are welcome with examples for different operating systems and telnet program implementations.

    1 answer 1

    unix-like operating systems

    Probably, bsd- and gnu-implementations are most often found here: netkit-telnet and inetutils-telnet . for the specified diagnosis, the difference between them is insignificant.


    An example of an unsuccessful connection to port 12345 on any of the servers, the ip-address of which resolves the name github.com :

     $ telnet github.com 12345 Trying 192.30.253.113... 

    You can interrupt an unsuccessful attempt using ctrl + c


    An example of a successful connection to the same server on port 22 :

     $ telnet 192.30.253.113 22 Trying 192.30.253.113... Connected to 192.30.253.113. Escape character is '^]'. SSH-2.0-libssh-0.7.0 

    The last line here is information from a program listening to port 22 on the polled server.

    if the connection was not immediately terminated by the listening program (it depends on its implementation and settings), then you can interrupt the telnet session by pressing the ctrl +] combination offered by the program and then the enter key, after which the telnet program prompt will appear:

     telnet> 

    in which you can enter the q command (or fully - quit ) and press the enter key.

    Microsoft Windows

    Actions are almost identical to the version for unix-like operating systems. Windows has a built-in telnet client, but it can be disabled. To enable it you need to follow the steps described on the Microsoft website .

    When everything is ready, you can start the telnet client like this:

    Start - Run - telnet - OK

    In the console window that opens, the following lines will be visible:

     Welcome to Microsoft Telnet Client Escape Character is 'CTRL+]' Microsoft Telnet> 

    To try to open a particular address and port, you need to write the letter o , and then the address and port. For example:

     Microsoft Telnet> o github.com 12345 
    • And where is the guarantee from the first example that this port does not obey in principle, despite the fact that the connection did not happen? - edem pm
    • I formulated exactly this way in the question, using the logical operator “and”: “accessible and listening”. Yes, it may be worthwhile to describe it in more detail in the question, but I tried to write more concisely and more simply. // highlighted font. - aleksandr barakin 3:17 pm
    • @edem, highlighted in font key designs. In general, the question-answer is written solely for the purpose of speeding up the search for a suitable link when discussing any network problems. - aleksandr barakin pm
    • Option for windows, by the way, is similar. Only here it is impossible to interrupt the attempt to connect using Ctrl+C - αλεχολυτ pm
    • @alexolut, as far as I remember, there is some other window that opens with the session itself. Could you please, if you have ms / windows at hand, write an answer variant, attaching a pair of explanatory pictures? - aleksandr barakin pm