DEV Community

Dmitry Romanoff
Dmitry Romanoff

Posted on

Python: How to check telnet status?

Here is Python code that checks telnet status.

import sys
import telnetlib

#host=sys.argv[1]
#portno=sys.argv[2]

host=input("enter hostname:")
portno=input("enter host number:")

try:
    conn = telnetlib.Telnet(host,portno)
    response = host+' ' + portno +' - Healthy'
except:
    response = host+' ' + portno +' - Unhealthy'
finally:
    print(response)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)