I want to find all the ports that are open on my localhost using telnet. I have set up a server using sockets on port 1234. I am using the following code to check whether a port is open or not
import getpass
import sys
import telnetlib
HOST = "127.0.0.1"
for port in range (1,65535):
try:
if(telnetlib.Telnet(HOST,port)):
print(port)
except ConnectionRefusedError as err:
print("connection refused")
However I get no output when I run this code. Appreciate any corrections in the code.Thanks