Search code examples
pythonpython-3.xtelnet

Check the status of a remote PC using telnet


How can I check the status of a remote PC using telnet from a python script?


Solution

  • If it has to be telnet, you can use the built-in telnetlib:

    from socketlib import timeout
    from telnetlib import Telnet
    
    try:
        Telnet("example.com", 23, 5)  # Timeout duration is 5 seconds
        print("Connected")
    except timeout:
        print("Timed out")