simple telnet module
Project description
xtelnet
This is an easy to use telnet module to interact with a remote system smoothly over this protocol!
Install :
pip install xtelnet
or
pip3 install xtelnet
Usage on a script :
import xtelnet
t=xtelnet.session()
ip='192.168.0.32'#just an example
t.login(ip, username='root',password='toor',p=23,timeout=5)
output1=t.execute('echo ala_is_king')
print(output1)
output2=t.execute('cd / && ls')
print(output2)
t.close()
To start a manual interactive session after login, just do:
import xtelnet
t=xtelnet.session()
ip='192.168.0.32'#just an example
t.login(ip, username='root',password='toor',p=23,timeout=5)
t.interact()
The session class contains all the data of the session (username, password, telnet's banner, prompt, prompt's end, session logs):
import xtelnet
t=xtelnet.session()
ip='192.168.0.32'#just an example
t.login(ip, username='root',password='toor',p=23,timeout=5)
t.execute('ls')
print(t.host)
print(t.port)
print(t.timeout)
print(t.connected)
print(t.username)
print(t.password)
print(t.banner)
print(t.prompt)
print(t.prompt_end)
print(t.logs)
To reset the session's saved data:
import xtelnet
t=xtelnet.session()
ip='192.168.0.32'#just an example
t.login(ip, username='root',password='toor',p=23,timeout=5)
t.execute('ls')
t.close()
t.reset_session()
To get the telnet's banner of the remote machine:
(no login)
import xtelnet
t=xtelnet.session()
ip='192.168.0.32'#just an example
banner=t.get_banner(ip,p=23,timeout=5)
print(banner)
(after login)
import xtelnet
t=xtelnet.session()
ip='192.168.0.32'#just an example
t.login(ip, username='root',password='toor',p=23,timeout=5)
banner=t.banner
print(banner)
Usage from command line :
python -m xtelnet host [options...]
options:
-username : set a username (required if username is needed to access)
-password : set a password (required if password is needed to access)
-port : (23 by default) set port
-timeout : (5 by default) set timeout
--add-command : a command to execute after login
--command-timeout : timeout for command execution
--set-newline : set a new line indecator("\n" or "\r\n")
--no-shell : disable shell after authentication
--help : get this help message
examples:
python -m xtelnet 127.0.0.1 -username root -password root --add-command "echo ala" --add-command "dir"
python -m xtelnet 127.0.0.1 -username root -password root -port 2323 -timeout 5
python -m xtelnet 127.0.0.1 -username root -password root -port 2323 -timeout 5 --no-shell
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.