dwapstra / telnetlib-proxy

Python telnetlib wrapper with SOCKS proxy support
Apache License 2.0
0 stars 0 forks source link

help using the library #1

Open gpmatos opened 9 months ago

gpmatos commented 9 months ago

Hello,

I found this library as Im trying to create a script in python that connects via telnet using a proxy server. As I'm new to the language your read me instructions feel kinda confusing. Using the script provided at the end of the web page were would you add your proxy part? https://docs.python.org/3/library/telnetlib.html#telnet-objects

iiie commented 4 months ago

@gpmatos Proxy is set with an environment variable telnet_proxy. Like the readme on this repo says:

export telnet_proxy=socks5://host:port
your_script.py

Looking at the code And the example you linked from telnetlib docs, here is an example using this library instead.

import getpass
from telnetlib_proxy import Telnet

HOST = "localhost"
user = input("Enter your remote account: ")
password = getpass.getpass()

tn = Telnet(HOST)

tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"ls\n")
tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))

I am not the author.