notacorn
notacorn

Reputation: 4079

How to check host connection port using python telnetlib3?

telnetlib3 is the new library since telnetlib is depracated in python 3.13.

I'm interested in being able to check on a port of a host whether it can make a connection. This answer works for me but only on the telnet on command line: https://stackoverflow.com/a/73417034/8652920

Indeed, running (echo ^]; echo quit) | timeout 5 telnet <REMOTEHOST> <REMOTEPORT> and checking the status code tells me whether the port is alive. But I want to do this in python so I don't have to worry about the user OS. I thought telnetlib3 would make this straightforward but honestly I'm pretty lost.

Python 3.12.5 (main, Aug  6 2024, 19:08:49) [Clang 15.0.0 (clang-1500.1.0.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import telnetlib3
>>> tn = telnetlib3.Telnet("host")

I'm pretty confused on what to do from here, how do I get the returncode like we got from command line?

Upvotes: 0

Views: 50

Answers (0)

Related Questions