<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python telnet in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4034152#M891</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I didn't test the script, but as &lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/286878"&gt;@balaji.bandi&lt;/a&gt; said, please post the error &amp;amp; the program's output.&lt;BR /&gt;&lt;BR /&gt;I have observed one problem from your script is in the following line:&lt;BR /&gt;&lt;BR /&gt;user = raw_input("Enter your username ")&lt;BR /&gt;&lt;BR /&gt;You may need to strip out the newline character inputted by user.&lt;BR /&gt;&lt;BR /&gt;user = raw_input("Enter Your username ")&lt;BR /&gt;user = user.rstrip()&lt;BR /&gt;&lt;BR /&gt;==&lt;BR /&gt;&lt;BR /&gt;For the python 3 in GNS3, it should be already included. You may simply call it by "python3".</description>
    <pubDate>Sat, 22 Feb 2020 19:03:34 GMT</pubDate>
    <dc:creator>ngkin2010</dc:creator>
    <dc:date>2020-02-22T19:03:34Z</dc:date>
    <item>
      <title>Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4034074#M889</link>
      <description>&lt;P&gt;Hello Gents,&lt;/P&gt;&lt;P&gt;&amp;nbsp;running below python 2 script in GNS3 ..telnet is successful but not configure IP address as I mentioned in the script...whats the issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import getpass&lt;BR /&gt;import sys&lt;BR /&gt;import telnetlib&lt;/P&gt;&lt;P&gt;HOST = "192.168.122.71"&lt;BR /&gt;user = raw_input("Enter your username ")&lt;BR /&gt;password = getpass.getpass()&lt;/P&gt;&lt;P&gt;tn = telnetlib.Telnet(HOST)&lt;/P&gt;&lt;P&gt;tn.read_until("Username: ")&lt;BR /&gt;tn.write(user + "\n")&lt;BR /&gt;if password:&lt;BR /&gt;tn.read_until("Password: ")&lt;BR /&gt;tn.write(password + "\n")&lt;/P&gt;&lt;P&gt;tn.write("enable\n")&lt;BR /&gt;tn.write("configure t\n")&lt;BR /&gt;tn.write("interface loopback0\n")&lt;BR /&gt;tn.write("ip address 1.1.1.1 255.255.255.255 \n")&lt;BR /&gt;print tn.read_all()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;amp; download python, go,perl, appllince in GNS3 but only running python 2 how to install python 3 in Appliance.?&lt;/P&gt;&lt;P&gt;Thank in advance&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 10:06:48 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4034074#M889</guid>
      <dc:creator>Network automation with python</dc:creator>
      <dc:date>2020-02-22T10:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4034096#M890</link>
      <description>&lt;P&gt;check manually is the user works, with given information - the user has enabled access?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not see any issue with the script here. ( what is the logs you get when you run the script) ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2020 13:15:29 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4034096#M890</guid>
      <dc:creator>balaji.bandi</dc:creator>
      <dc:date>2020-02-22T13:15:29Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4034152#M891</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I didn't test the script, but as &lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/286878"&gt;@balaji.bandi&lt;/a&gt; said, please post the error &amp;amp; the program's output.&lt;BR /&gt;&lt;BR /&gt;I have observed one problem from your script is in the following line:&lt;BR /&gt;&lt;BR /&gt;user = raw_input("Enter your username ")&lt;BR /&gt;&lt;BR /&gt;You may need to strip out the newline character inputted by user.&lt;BR /&gt;&lt;BR /&gt;user = raw_input("Enter Your username ")&lt;BR /&gt;user = user.rstrip()&lt;BR /&gt;&lt;BR /&gt;==&lt;BR /&gt;&lt;BR /&gt;For the python 3 in GNS3, it should be already included. You may simply call it by "python3".</description>
      <pubDate>Sat, 22 Feb 2020 19:03:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4034152#M891</guid>
      <dc:creator>ngkin2010</dc:creator>
      <dc:date>2020-02-22T19:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4080820#M892</link>
      <description>&lt;P&gt;i cant telnet, it hanged for10 mins then giving me below error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;root@NetworkAutomation-1:~# python3 telnettoswitch.py&lt;BR /&gt;Enter your telnet username: cisco&lt;BR /&gt;Password:&lt;BR /&gt;Traceback (most recent call last):&lt;BR /&gt;File "telnettoswitch.py", line 13, in &amp;lt;module&amp;gt;&lt;BR /&gt;tn.read_until(b"Password: ")&lt;BR /&gt;File "/usr/lib/python3.8/telnetlib.py", line 329, in read_until&lt;BR /&gt;return self.read_very_lazy()&lt;BR /&gt;File "/usr/lib/python3.8/telnetlib.py", line 405, in read_very_lazy&lt;BR /&gt;raise EOFError('telnet connection closed')&lt;BR /&gt;EOFError: telnet connection closed&lt;BR /&gt;root@NetworkAutomation-1:~#&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the script&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import getpass&lt;BR /&gt;import telnetlib&lt;/P&gt;&lt;P&gt;HOST = "192.168.122.3"&lt;BR /&gt;user = input("Enter your telnet username: ")&lt;BR /&gt;password = getpass.getpass()&lt;/P&gt;&lt;P&gt;tn = telnetlib.Telnet(HOST)&lt;/P&gt;&lt;P&gt;tn.read_until(b"username: ")&lt;BR /&gt;tn.write(user.encode('ascii') + b"\n")&lt;BR /&gt;if password:&lt;BR /&gt;tn.read_until(b"Password: ")&lt;BR /&gt;tn.write(password.encode('ascii') + b"\n")&lt;/P&gt;&lt;P&gt;tn.write(b"enable \n")&lt;BR /&gt;tn.write(b"passme \n")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;print(tn.read_all().decode('ascii'))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2020 21:10:50 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4080820#M892</guid>
      <dc:creator>yousefbamarof</dc:creator>
      <dc:date>2020-05-06T21:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4080821#M893</link>
      <description />
      <pubDate>Wed, 06 May 2020 21:11:52 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4080821#M893</guid>
      <dc:creator>yousefbamarof</dc:creator>
      <dc:date>2020-05-06T21:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4081752#M894</link>
      <description>&lt;P&gt;Your telnet session was closed before reaching the line 13.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason is because your script have inputted wrong password to the switch (even you have inputted the correct password).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find the explanation as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;import getpass
import telnetlib

HOST = "192.168.122.3"
user = &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;input("Enter your telnet username: ")&lt;BR /&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT color="#FF00FF"&gt;// After this line of code has executed, you read user's input (including the &lt;EM&gt;newline char: &lt;STRONG&gt;\n&lt;/STRONG&gt;&lt;/EM&gt;)&lt;BR /&gt;// Meaning that your 'user' variable is something like user = "username&lt;STRONG&gt;\n&lt;/STRONG&gt;"&lt;/FONT&gt;
&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;// You need to remove the unwanted tailing \n by adding the following code&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;user = user.rstrip()&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"username: ")&lt;BR /&gt;
tn.write(user.encode('ascii') + b"\n")&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;//Otherwise, when your script passing the variable 'user' with your additional tailing b"\n"&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;//which will become "username&lt;STRONG&gt;\n\n&lt;/STRONG&gt;"&lt;BR /&gt;//which mean you hit the enter twice, in other word, you enter an empty password to the switch.&lt;/FONT&gt;&lt;BR /&gt;
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 06:08:46 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4081752#M894</guid>
      <dc:creator>ngkin2010</dc:creator>
      <dc:date>2020-05-08T06:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4411463#M895</link>
      <description>&lt;P&gt;Did not work...showing the same error!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;tn.read_until(b"Password: ")&lt;BR /&gt;File "/usr/lib/python3.8/telnetlib.py", line 329, in read_until&lt;BR /&gt;return self.read_very_lazy()&lt;BR /&gt;File "/usr/lib/python3.8/telnetlib.py", line 405, in read_very_lazy&lt;BR /&gt;raise EOFError('telnet connectio")&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 14:30:21 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4411463#M895</guid>
      <dc:creator>Grey Hat</dc:creator>
      <dc:date>2021-06-01T14:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4420253#M896</link>
      <description>&lt;P&gt;If you follow the console on GNS3 for the device while the script is running it may give you some clues,&amp;nbsp; only thing may be the space after the subnet mask I can see&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dean&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jun 2021 14:32:08 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4420253#M896</guid>
      <dc:creator>DeanMoore</dc:creator>
      <dc:date>2021-06-18T14:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Python telnet</title>
      <link>https://community.cisco.com/t5/controllers/python-telnet/m-p/4739909#M897</link>
      <description>&lt;P&gt;Try below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;root@NetworkAutomation-1:~# cat script1&lt;BR /&gt;import getpass&lt;BR /&gt;import telnetlib&lt;/P&gt;&lt;P&gt;HOST = "Router IP address"&lt;BR /&gt;user = input("Enter your telnet username: ")&lt;BR /&gt;user = user.rstrip()&lt;BR /&gt;password = getpass.getpass()&lt;/P&gt;&lt;P&gt;tn = telnetlib.Telnet(HOST)&lt;/P&gt;&lt;P&gt;tn.read_until(b"Username: ")&lt;BR /&gt;tn.write(user.encode('ascii') + b"\n")&lt;BR /&gt;if password:&lt;BR /&gt;tn.read_until(b"Password: ")&lt;BR /&gt;tn.write(password.encode('ascii') + b"\n")&lt;/P&gt;&lt;P&gt;tn.write(b"enable\n")&lt;BR /&gt;tn.write(b"cisco\n")&lt;BR /&gt;tn.write(b"conf t\n")&lt;BR /&gt;tn.write(b"int l0\n")&lt;BR /&gt;tn.write(b"ip address 1.1.1.1 255.255.255.255\n")&lt;BR /&gt;tn.write(b"end\n")&lt;BR /&gt;tn.write(b"exit\n")&lt;/P&gt;&lt;P&gt;print(tn.read_all().decode('ascii'))&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2022 20:14:04 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/python-telnet/m-p/4739909#M897</guid>
      <dc:creator>Spam-Mail</dc:creator>
      <dc:date>2022-12-15T20:14:04Z</dc:date>
    </item>
  </channel>
</rss>

