Skip to main content

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.connect(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.connect(ip, username='root',password='toor',p=23,timeout=5)
t.interact()

The multi_session helps you in controlling multiple telnet sessions in parallel:

import xtelnet
t=xtelnet.multi_session()
ip1='192.168.0.32'#just an example
ip2='192.168.0.4'
ip3='192.168.0.10'
ip4='192.168.0.11'
ip5='192.168.0.12'
host1=xtelnet.dict_host(ip1, username='root',password='toor',p=23,timeout=5)
host2=xtelnet.dict_host(ip2, username='root',password='toor',p=23,timeout=5)
host3=xtelnet.dict_host(ip3, username='root',password='toor',p=23,timeout=5)
host4=xtelnet.dict_host(ip4, username='root',password='toor',p=23,timeout=5)
host5=xtelnet.dict_host(ip5, username='root',password='toor',p=23,timeout=5)
t.connect([host1,host2,host3,host4,host5])
print(t.sessions)#to see the connected hosts
c=t.all_execute('echo "ala is king"')#execute this command on all hosts
print(c)#print output
c=t.some_execute([ip1,ip2],'echo "ala is king"')#execute this command on some hosts
print(c)
c=t.host_execute(ip1,'echo "ala is king"')#execute this command on this host
print(c)
t.disconnect_host(ip1)#to disconnect of this host
t.disconnect_some([ip2,ip3])#to disconnect of those hosts
t.disconnect_all()#to disconnect of all hosts

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for xtelnet, version 1.2.1
Filename, size File type Python version Upload date Hashes
Filename, size xtelnet-1.2.1.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page