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.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


Download files

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

Source Distribution

xtelnet-1.1.5.tar.gz (4.5 kB view details)

Uploaded Source

File details

Details for the file xtelnet-1.1.5.tar.gz.

File metadata

  • Download URL: xtelnet-1.1.5.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/2.7.17

File hashes

Hashes for xtelnet-1.1.5.tar.gz
Algorithm Hash digest
SHA256 2bb0a1f1050582e4e6baab7a4c069a7fbe2541bf5b6deb02d9d5a38b06ef6608
MD5 a0c1816a9bf7b1872effe050cfa6bdd2
BLAKE2b-256 c99ad619c521fdd595a1bd13e8452d0b0103ff1ea2a0026303f3a3e6fc0b68d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page