xtelnet


Namextelnet JSON
Version 2.2.7 PyPI version JSON
download
home_pagehttps://github.com/AlaBouali/xtelnet
Summarythe best alternative to telnetlib as a telnet client
upload_time2024-03-29 16:08:41
maintainerNone
docs_urlNone
authorAlaBouali
requires_python>=2.7
licenseMIT License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # xtelnet
This is an easy to use telnet module to interact with a remote system smoothly over this protocol! It is a very minimalistic alterative to "telnetlib". xtelnet is a powerful and user-friendly Python library designed for managing Telnet sessions with ease and efficiency. With its intuitive interface and robust functionality, xtelnet simplifies the process of interacting with Telnet servers, offering a range of features for seamless communication. xtelnet offers a comprehensive solution for Telnet communication, providing developers with the tools they need to effectively manage Telnet sessions and interact with remote systems. Whether you're a seasoned developer or new to Telnet protocols, xtelnet empowers you to achieve your goals efficiently and reliably.

# Why should I use xtelnet?

<ul>
  <li>Easy to use and stable</li>
  <li>Simple Authentication mechanism</li>
  <li>Handle telnet negotiations automatically for you</li>
  <li>Compatible with python 2 and 3</li>
  <li>Set custom Telnet negotiation options</li>
  <li>parse commands output and returns only necessary output ( command's ouput, nothing extra )</li>
  <li>Compatible with almost all servers when it comes to authentication and executing the commands</li>
  <li>Available Command line tool</li>
  <li>Thread-safe: if the session is shared among threads to execute commands, the commands will be executed one by one</li>
  <li>Supports running multiple sessions concurrently</li>
  <li>Can connect simultaneously and run in parallel the same command on: single or some or all connected hosts</li>
  <li>Allow reconnect after closing the connection</li>
  <li>Allow escape ANSI characters</li>
  <li>Grab banners</li>
  <li>Available "ping" function to use if you want to keep the connection open</li>
  <li>Supports SOCKS 4 / 5 proxies</li>
  <li>Supports SSL</li>
  <li>Supports sending JSON data</li>
</ul>

# Install :

<div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">pip install xtelnet
</pre></div>


or

<div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">pip3 install xtelnet
</pre></div>


# Usage on a script :

<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">xtelnet</span>
t<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Telnet_Session()
ip<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;192.168.0.32&#39;</span><span style="color: #888888">#just an example</span>
# if you are using "stupid" tcp servers, just set "allow_raw_tcp" parameter in "connect" method to true and it will stream everything over TCP
t<span style="color: #333333">.</span>connect(ip, username<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;root&#39;</span>,password<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;toor&#39;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>,timeout<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">5</span>)
output1<span style="color: #333333">=</span>t<span style="color: #333333">.</span>execute(<span style="background-color: #fff0f0">&#39;echo ala_is_king&#39;</span>,timeout=5,buffer_read_timeout=2,remove_prompt_from_output=True,max_empty_buffers=3)
<span style="color: #008800; font-weight: bold">print</span>(output1)
output2<span style="color: #333333">=</span>t<span style="color: #333333">.</span>execute(<span style="background-color: #fff0f0">&#39;cd / &amp;&amp; ls&#39;</span>)
<span style="color: #008800; font-weight: bold">print</span>(output2)
output3<span style="color: #333333">=</span>t<span style="color: #333333">.</span>execute(<span style="background-color: #fff0f0">&#39;cd / &amp;&amp; ls&#39;</span>,read_until_match='expected_string_here')
<span style="color: #008800; font-weight: bold">print</span>(output3)
t<span style="color: #333333">.</span>close()<span style="color: #888888">#close the connection but keep the connection string to do reconnect later</span>
t<span style="color: #333333">.</span>enable_debug()<span style="color: #888888"># enable debug mode</span>
t<span style="color: #333333">.</span>disable_debug()<span style="color: #888888"># disable debug mode</span>
t<span style="color: #333333">.</span>reconnect()<span style="color: #888888">#reconnect to the host with the previous parameters</span>
t<span style="color: #333333">.</span>ping()<span style="color: #888888">#send new line to the host to keep the connectio open</span>
t<span style="color: #333333">.</span>destroy()<span style="color: #888888">#close the connection and remove the connection string totally, after this you can&#39;t do &quot;reconnect&quot;</span>
</pre></div>
<div style="background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%">t.connect('114.35.81.134',proxy_type=5,proxy_host='localhost',proxy_port=9150,proxy_username='user',proxy_password='pass')#use SOCKS5 proxy to connect, set 'proxy_type' to 4 to use SOCKS4 
</pre></div>

<!--
<h3>To start a manual interactive session after login, just do:</h3>


<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">xtelnet</span>
t<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>session()
ip<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;192.168.0.32&#39;</span><span style="color: #888888">#just an example</span>
t<span style="color: #333333">.</span>connect(ip, username<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;root&#39;</span>,password<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;toor&#39;</span>,p<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>,timeout<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">5</span>)
t<span style="color: #333333">.</span>interact()
</pre></div>




-->
<h3>The multi_session helps you in controlling multiple telnet sessions in parallel:</h3>



<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">xtelnet</span>
t<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Multi_Telnet_Session()
ip1<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;192.168.0.32&#39;</span><span style="color: #888888">#just an example</span>
ip2<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;192.168.0.4&#39;</span>
ip3<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;192.168.0.10&#39;</span>
ip4<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;192.168.0.11&#39;</span>
ip5<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;192.168.0.12&#39;</span>
host1<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Telnet_Session.setup_host_configs(ip1, username<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;root&#39;</span>,password<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;toor&#39;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>,timeout<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">5</span>)
host2<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Telnet_Session.setup_host_configs(ip2, username<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;root&#39;</span>,password<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;toor&#39;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>,timeout<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">5</span>)
host3<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Telnet_Session.setup_host_configs(ip3, username<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;root&#39;</span>,password<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;toor&#39;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>,timeout<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">5</span>)
host4<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Telnet_Session.setup_host_configs(ip4, username<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;root&#39;</span>,password<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;toor&#39;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>,timeout<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">5</span>)
host5<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Telnet_Session.setup_host_configs(ip5, username<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;root&#39;</span>,password<span style="color: #333333">=</span><span style="background-color: #fff0f0">&#39;toor&#39;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>,timeout<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">5</span>)
t<span style="color: #333333">.</span>connect([host1,host2,host3,host4,host5])
<span style="color: #008800; font-weight: bold">print</span>(t<span style="color: #333333">.</span>sessions)<span style="color: #888888">#to see the connected hosts</span>
c<span style="color: #333333">=</span>t<span style="color: #333333">.</span>all_execute(<span style="background-color: #fff0f0">&#39;echo &quot;ala is king&quot;&#39;</span>)<span style="color: #888888">#execute this command on all hosts</span>
<span style="color: #008800; font-weight: bold">print</span>(c)<span style="color: #888888">#print output</span>
c<span style="color: #333333">=</span>t<span style="color: #333333">.</span>some_execute([ip1,ip2],<span style="background-color: #fff0f0">&#39;echo &quot;ala is king&quot;&#39;</span>)<span style="color: #888888">#execute this command on some hosts</span>
<span style="color: #008800; font-weight: bold">print</span>(c)
c<span style="color: #333333">=</span>t<span style="color: #333333">.</span>host_execute(ip1,<span style="background-color: #fff0f0">&#39;echo &quot;ala is king&quot;&#39;</span>)<span style="color: #888888">#execute this command on this host</span>
<span style="color: #008800; font-weight: bold">print</span>(c)
t<span style="color: #333333">.</span>disconnect_host(ip1)<span style="color: #888888">#to disconnect of this host</span>
t<span style="color: #333333">.</span>disconnect_some([ip2,ip3])<span style="color: #888888">#to disconnect of those hosts</span>
t<span style="color: #333333">.</span>disconnect_all()<span style="color: #888888">#to disconnect of all hosts</span>
t<span style="color: #333333">.</span>destroy()<span style="color: #888888">#disconnect from all hosts</span>
</pre></div>





# Usage from command line :

<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #888888">xtelnet host [options...]</span>

<span style="color: #888888">options:</span>


<span style="color: #888888">-username : set a username (required if username is needed to access)</span>
<span style="color: #888888">-password : set a password (required if password is needed to access)</span>
<span style="color: #888888">-port : (23 by default) set port</span>
<span style="color: #888888">-timeout : (5 by default) set timeout</span>
<span style="color: #888888">--add-command : a command to execute after login and disable shell</span>
<span style="color: #888888">--set-newline : (&quot;\\n&quot; by default) set a new line indecator(&quot;\\n&quot; or &quot;\\r\\n&quot;)</span>
<span style="color: #888888">--no-shell : (enabled by default if no commands are specified) disable shell after authentication</span>
<span style="color: #888888">--read-retries : times to retry reading the response if it takes too long</span>
<span style="color: #888888">--help : get this help message</span>

<span style="color: #888888">examples:</span>

<span style="color: #888888">xtelnet 127.0.0.1 -username root -password root --add-command &quot;echo ala&quot; --add-command &quot;dir&quot;</span>

<span style="color: #888888">xtelnet 127.0.0.1 -username root -password root -port 2323 -timeout 5</span>

<span style="color: #888888">xtelnet 127.0.0.1 -username root -password root -port 2323 -timeout 5 --no-shell</span>
</pre></div>


# Xtelnet can be used to grab banners:


<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">xtelnet</span>
telnet_banner<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Socket_Connection.get_banner(<span style="background-color: #fff0f0">&quot;localhost&quot;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">23</span>)<span style="color: #888888">#suppose you have telnet server running on that port</span>

http_banner<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Socket_Connection.get_banner(<span style="background-color: #fff0f0">&quot;www.google.com&quot;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">80</span>,payload<span style="color: #333333">=</span><span style="background-color: #fff0f0">&quot;GET / HTTP/1.1</span><span style="color: #666666; font-weight: bold; background-color: #fff0f0">\r\n</span><span style="background-color: #fff0f0">Host: www.google.com</span><span style="color: #666666; font-weight: bold; background-color: #fff0f0">\r\n\r\n</span><span style="background-color: #fff0f0">&quot;</span>)<span style="color: #888888">#we send a http request as a payload to get the response</span>

ssh_banner<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Socket_Connection.get_banner(<span style="background-color: #fff0f0">&quot;localhost&quot;</span>,port<span style="color: #333333">=</span><span style="color: #0000DD; font-weight: bold">22</span>)
</pre></div>




# Xtelnet can escape all ANSI characters :


<div style="background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #008800; font-weight: bold">import</span> <span style="color: #0e84b5; font-weight: bold">xtelnet</span>
escaped_string<span style="color: #333333">=</span>xtelnet<span style="color: #333333">.</span>Socket_Connection.escape_ansi( unescaped_string )
</pre></div>


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/AlaBouali/xtelnet",
    "name": "xtelnet",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=2.7",
    "maintainer_email": null,
    "keywords": null,
    "author": "AlaBouali",
    "author_email": "ala.bouali.1997@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3c/a8/5fef4686eb4b658b8274f455bdb352e384f3c8e56aab16d27623209775b4/xtelnet-2.2.7.tar.gz",
    "platform": null,
    "description": "# xtelnet\r\nThis is an easy to use telnet module to interact with a remote system smoothly over this protocol! It is a very minimalistic alterative to \"telnetlib\". xtelnet is a powerful and user-friendly Python library designed for managing Telnet sessions with ease and efficiency. With its intuitive interface and robust functionality, xtelnet simplifies the process of interacting with Telnet servers, offering a range of features for seamless communication. xtelnet offers a comprehensive solution for Telnet communication, providing developers with the tools they need to effectively manage Telnet sessions and interact with remote systems. Whether you're a seasoned developer or new to Telnet protocols, xtelnet empowers you to achieve your goals efficiently and reliably.\r\n\r\n# Why should I use xtelnet?\r\n\r\n<ul>\r\n  <li>Easy to use and stable</li>\r\n  <li>Simple Authentication mechanism</li>\r\n  <li>Handle telnet negotiations automatically for you</li>\r\n  <li>Compatible with python 2 and 3</li>\r\n  <li>Set custom Telnet negotiation options</li>\r\n  <li>parse commands output and returns only necessary output ( command's ouput, nothing extra )</li>\r\n  <li>Compatible with almost all servers when it comes to authentication and executing the commands</li>\r\n  <li>Available Command line tool</li>\r\n  <li>Thread-safe: if the session is shared among threads to execute commands, the commands will be executed one by one</li>\r\n  <li>Supports running multiple sessions concurrently</li>\r\n  <li>Can connect simultaneously and run in parallel the same command on: single or some or all connected hosts</li>\r\n  <li>Allow reconnect after closing the connection</li>\r\n  <li>Allow escape ANSI characters</li>\r\n  <li>Grab banners</li>\r\n  <li>Available \"ping\" function to use if you want to keep the connection open</li>\r\n  <li>Supports SOCKS 4 / 5 proxies</li>\r\n  <li>Supports SSL</li>\r\n  <li>Supports sending JSON data</li>\r\n</ul>\r\n\r\n# Install :\r\n\r\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\">pip install xtelnet\r\n</pre></div>\r\n\r\n\r\nor\r\n\r\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\">pip3 install xtelnet\r\n</pre></div>\r\n\r\n\r\n# Usage on a script :\r\n\r\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">xtelnet</span>\r\nt<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Telnet_Session()\r\nip<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;192.168.0.32&#39;</span><span style=\"color: #888888\">#just an example</span>\r\n# if you are using \"stupid\" tcp servers, just set \"allow_raw_tcp\" parameter in \"connect\" method to true and it will stream everything over TCP\r\nt<span style=\"color: #333333\">.</span>connect(ip, username<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;root&#39;</span>,password<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;toor&#39;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>,timeout<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">5</span>)\r\noutput1<span style=\"color: #333333\">=</span>t<span style=\"color: #333333\">.</span>execute(<span style=\"background-color: #fff0f0\">&#39;echo ala_is_king&#39;</span>,timeout=5,buffer_read_timeout=2,remove_prompt_from_output=True,max_empty_buffers=3)\r\n<span style=\"color: #008800; font-weight: bold\">print</span>(output1)\r\noutput2<span style=\"color: #333333\">=</span>t<span style=\"color: #333333\">.</span>execute(<span style=\"background-color: #fff0f0\">&#39;cd / &amp;&amp; ls&#39;</span>)\r\n<span style=\"color: #008800; font-weight: bold\">print</span>(output2)\r\noutput3<span style=\"color: #333333\">=</span>t<span style=\"color: #333333\">.</span>execute(<span style=\"background-color: #fff0f0\">&#39;cd / &amp;&amp; ls&#39;</span>,read_until_match='expected_string_here')\r\n<span style=\"color: #008800; font-weight: bold\">print</span>(output3)\r\nt<span style=\"color: #333333\">.</span>close()<span style=\"color: #888888\">#close the connection but keep the connection string to do reconnect later</span>\r\nt<span style=\"color: #333333\">.</span>enable_debug()<span style=\"color: #888888\"># enable debug mode</span>\r\nt<span style=\"color: #333333\">.</span>disable_debug()<span style=\"color: #888888\"># disable debug mode</span>\r\nt<span style=\"color: #333333\">.</span>reconnect()<span style=\"color: #888888\">#reconnect to the host with the previous parameters</span>\r\nt<span style=\"color: #333333\">.</span>ping()<span style=\"color: #888888\">#send new line to the host to keep the connectio open</span>\r\nt<span style=\"color: #333333\">.</span>destroy()<span style=\"color: #888888\">#close the connection and remove the connection string totally, after this you can&#39;t do &quot;reconnect&quot;</span>\r\n</pre></div>\r\n<div style=\"background: #f8f8f8; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\">t.connect('114.35.81.134',proxy_type=5,proxy_host='localhost',proxy_port=9150,proxy_username='user',proxy_password='pass')#use SOCKS5 proxy to connect, set 'proxy_type' to 4 to use SOCKS4 \r\n</pre></div>\r\n\r\n<!--\r\n<h3>To start a manual interactive session after login, just do:</h3>\r\n\r\n\r\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">xtelnet</span>\r\nt<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>session()\r\nip<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;192.168.0.32&#39;</span><span style=\"color: #888888\">#just an example</span>\r\nt<span style=\"color: #333333\">.</span>connect(ip, username<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;root&#39;</span>,password<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;toor&#39;</span>,p<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>,timeout<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">5</span>)\r\nt<span style=\"color: #333333\">.</span>interact()\r\n</pre></div>\r\n\r\n\r\n\r\n\r\n-->\r\n<h3>The multi_session helps you in controlling multiple telnet sessions in parallel:</h3>\r\n\r\n\r\n\r\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">xtelnet</span>\r\nt<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Multi_Telnet_Session()\r\nip1<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;192.168.0.32&#39;</span><span style=\"color: #888888\">#just an example</span>\r\nip2<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;192.168.0.4&#39;</span>\r\nip3<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;192.168.0.10&#39;</span>\r\nip4<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;192.168.0.11&#39;</span>\r\nip5<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;192.168.0.12&#39;</span>\r\nhost1<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Telnet_Session.setup_host_configs(ip1, username<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;root&#39;</span>,password<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;toor&#39;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>,timeout<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">5</span>)\r\nhost2<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Telnet_Session.setup_host_configs(ip2, username<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;root&#39;</span>,password<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;toor&#39;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>,timeout<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">5</span>)\r\nhost3<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Telnet_Session.setup_host_configs(ip3, username<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;root&#39;</span>,password<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;toor&#39;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>,timeout<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">5</span>)\r\nhost4<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Telnet_Session.setup_host_configs(ip4, username<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;root&#39;</span>,password<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;toor&#39;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>,timeout<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">5</span>)\r\nhost5<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Telnet_Session.setup_host_configs(ip5, username<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;root&#39;</span>,password<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&#39;toor&#39;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>,timeout<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">5</span>)\r\nt<span style=\"color: #333333\">.</span>connect([host1,host2,host3,host4,host5])\r\n<span style=\"color: #008800; font-weight: bold\">print</span>(t<span style=\"color: #333333\">.</span>sessions)<span style=\"color: #888888\">#to see the connected hosts</span>\r\nc<span style=\"color: #333333\">=</span>t<span style=\"color: #333333\">.</span>all_execute(<span style=\"background-color: #fff0f0\">&#39;echo &quot;ala is king&quot;&#39;</span>)<span style=\"color: #888888\">#execute this command on all hosts</span>\r\n<span style=\"color: #008800; font-weight: bold\">print</span>(c)<span style=\"color: #888888\">#print output</span>\r\nc<span style=\"color: #333333\">=</span>t<span style=\"color: #333333\">.</span>some_execute([ip1,ip2],<span style=\"background-color: #fff0f0\">&#39;echo &quot;ala is king&quot;&#39;</span>)<span style=\"color: #888888\">#execute this command on some hosts</span>\r\n<span style=\"color: #008800; font-weight: bold\">print</span>(c)\r\nc<span style=\"color: #333333\">=</span>t<span style=\"color: #333333\">.</span>host_execute(ip1,<span style=\"background-color: #fff0f0\">&#39;echo &quot;ala is king&quot;&#39;</span>)<span style=\"color: #888888\">#execute this command on this host</span>\r\n<span style=\"color: #008800; font-weight: bold\">print</span>(c)\r\nt<span style=\"color: #333333\">.</span>disconnect_host(ip1)<span style=\"color: #888888\">#to disconnect of this host</span>\r\nt<span style=\"color: #333333\">.</span>disconnect_some([ip2,ip3])<span style=\"color: #888888\">#to disconnect of those hosts</span>\r\nt<span style=\"color: #333333\">.</span>disconnect_all()<span style=\"color: #888888\">#to disconnect of all hosts</span>\r\nt<span style=\"color: #333333\">.</span>destroy()<span style=\"color: #888888\">#disconnect from all hosts</span>\r\n</pre></div>\r\n\r\n\r\n\r\n\r\n\r\n# Usage from command line :\r\n\r\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #888888\">xtelnet host [options...]</span>\r\n\r\n<span style=\"color: #888888\">options:</span>\r\n\r\n\r\n<span style=\"color: #888888\">-username : set a username (required if username is needed to access)</span>\r\n<span style=\"color: #888888\">-password : set a password (required if password is needed to access)</span>\r\n<span style=\"color: #888888\">-port : (23 by default) set port</span>\r\n<span style=\"color: #888888\">-timeout : (5 by default) set timeout</span>\r\n<span style=\"color: #888888\">--add-command : a command to execute after login and disable shell</span>\r\n<span style=\"color: #888888\">--set-newline : (&quot;\\\\n&quot; by default) set a new line indecator(&quot;\\\\n&quot; or &quot;\\\\r\\\\n&quot;)</span>\r\n<span style=\"color: #888888\">--no-shell : (enabled by default if no commands are specified) disable shell after authentication</span>\r\n<span style=\"color: #888888\">--read-retries : times to retry reading the response if it takes too long</span>\r\n<span style=\"color: #888888\">--help : get this help message</span>\r\n\r\n<span style=\"color: #888888\">examples:</span>\r\n\r\n<span style=\"color: #888888\">xtelnet 127.0.0.1 -username root -password root --add-command &quot;echo ala&quot; --add-command &quot;dir&quot;</span>\r\n\r\n<span style=\"color: #888888\">xtelnet 127.0.0.1 -username root -password root -port 2323 -timeout 5</span>\r\n\r\n<span style=\"color: #888888\">xtelnet 127.0.0.1 -username root -password root -port 2323 -timeout 5 --no-shell</span>\r\n</pre></div>\r\n\r\n\r\n# Xtelnet can be used to grab banners:\r\n\r\n\r\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">xtelnet</span>\r\ntelnet_banner<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Socket_Connection.get_banner(<span style=\"background-color: #fff0f0\">&quot;localhost&quot;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">23</span>)<span style=\"color: #888888\">#suppose you have telnet server running on that port</span>\r\n\r\nhttp_banner<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Socket_Connection.get_banner(<span style=\"background-color: #fff0f0\">&quot;www.google.com&quot;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">80</span>,payload<span style=\"color: #333333\">=</span><span style=\"background-color: #fff0f0\">&quot;GET / HTTP/1.1</span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n</span><span style=\"background-color: #fff0f0\">Host: www.google.com</span><span style=\"color: #666666; font-weight: bold; background-color: #fff0f0\">\\r\\n\\r\\n</span><span style=\"background-color: #fff0f0\">&quot;</span>)<span style=\"color: #888888\">#we send a http request as a payload to get the response</span>\r\n\r\nssh_banner<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Socket_Connection.get_banner(<span style=\"background-color: #fff0f0\">&quot;localhost&quot;</span>,port<span style=\"color: #333333\">=</span><span style=\"color: #0000DD; font-weight: bold\">22</span>)\r\n</pre></div>\r\n\r\n\r\n\r\n\r\n# Xtelnet can escape all ANSI characters :\r\n\r\n\r\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\"><pre style=\"margin: 0; line-height: 125%\"><span style=\"color: #008800; font-weight: bold\">import</span> <span style=\"color: #0e84b5; font-weight: bold\">xtelnet</span>\r\nescaped_string<span style=\"color: #333333\">=</span>xtelnet<span style=\"color: #333333\">.</span>Socket_Connection.escape_ansi( unescaped_string )\r\n</pre></div>\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "the best alternative to telnetlib as a telnet client",
    "version": "2.2.7",
    "project_urls": {
        "Homepage": "https://github.com/AlaBouali/xtelnet"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3ca85fef4686eb4b658b8274f455bdb352e384f3c8e56aab16d27623209775b4",
                "md5": "c84883222535835c885b26d344a1b61e",
                "sha256": "c2e439a7b30375b0774a50b76c7c1f5933c9384b0bc804f9cf4d03b043cf5b52"
            },
            "downloads": -1,
            "filename": "xtelnet-2.2.7.tar.gz",
            "has_sig": false,
            "md5_digest": "c84883222535835c885b26d344a1b61e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=2.7",
            "size": 15103,
            "upload_time": "2024-03-29T16:08:41",
            "upload_time_iso_8601": "2024-03-29T16:08:41.074958Z",
            "url": "https://files.pythonhosted.org/packages/3c/a8/5fef4686eb4b658b8274f455bdb352e384f3c8e56aab16d27623209775b4/xtelnet-2.2.7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-29 16:08:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "AlaBouali",
    "github_project": "xtelnet",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "xtelnet"
}
        
Elapsed time: 0.20502s