We help IT Professionals succeed at work.
Private
Troubleshooting Question

router cannot get interface configuration

eemoon
eemoon asked
on
62 Views
Last Modified: 2020-10-24
Hi Anyone can help to take a look at why the loopback0 configuration cannot be sent to router(R1) by NetworkAutomation-1 which is connected to R1 directly and correctly. R1 can get telnet info, but its loopback interface cannot be configured. The follow are all info that I have.

root@NetworkAutomation-1:~# python pythonr1
Enter your remote account: cisco
Password:
Traceback (most recent call last):
  File "pythonr1", line 15, in <module>
    tn.read_until("Password: ")
  File "/usr/lib/python2.7/telnetlib.py", line 294, in read_until
    return self._read_until_with_poll(match, timeout)
  File "/usr/lib/python2.7/telnetlib.py", line 343, in _read_until_with_poll
    return self.read_very_lazy()
  File "/usr/lib/python2.7/telnetlib.py", line 455, in read_very_lazy
    raise EOFError, 'telnet connection closed'
EOFError: telnet connection closed
root@NetworkAutomation-1:~#


The following are configuration of python and debug telnet info on R1

Here is configuration:
root@NetworkAutomation-1:~# cat pythonr1
import getpass
import sys
import telnetlib

HOST = "192.168.0.1"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.write(b'\n')
tn.read_until("username: ")
tn.write(user + "\n")
if password:
    tn.read_until("Password: ")
    tn.write(password + "\n")

tn.write("enable\n")
tn.write("cisco\n")
tn.write("config t\n")
tn.write("interface loop 0\n")
tn.write("ip address 1.1.1.1 255.255.255.255\n")
tn.write("end\n")
tn.write("exit\n")
print tn.read_all()


R1#
debug telnet 
*Oct 18 09:22:37.179: Telnet2: 1 1 251 1
*Oct 18 09:22:37.179: TCP2: Telnet sent WILL ECHO (1)
*Oct 18 09:22:37.179: Telnet2: 2 2 251 3
*Oct 18 09:22:37.179: TCP2: Telnet sent WILL SUPPRESS-GA (3)
*Oct 18 09:22:37.179: Telnet2: 80000 80000 253 24
*Oct 18 09:22:37.179: TCP2: Telnet sent DO TTY-TYPE (24)
*Oct 18 09:22:37.179: Telnet2: 10000000 10000000 253 31
*Oct 18 09:22:37.179: TCP2: Telnet sent DO WINDOW-SIZE (31)
*Oct 18 09:22:37.191: TCP2: Telnet received DONT ECHO (1)
*Oct 18 09:22:37.191: TCP2: Telnet sent WONT ECHO (1)
*Oct 18 09:22:37.203: TCP2: Telnet received DONT SUPPRESS-GA (3)
*Oct 18 09:22:37.203: TCP2: Telnet sent WONT SUPPRESS-GA (3)
*Oct 18 09:22:37.207: TCP2: Telnet received WONT TTY-TYPE (24)
*Oct 18 09:22:37.207: TCP2: Telnet sent DONT TTY-TYPE (24)
*Oct 18 09:22:37.207: TCP2: Telnet received WONT WINDOW-SIZE (31)
*Oct 18 09:22:37.211: TCP2: Telnet sent DONT WINDOW-SIZE (31)
*Oct 18 09:22:37.243: TCP2: Telnet received DONT ECHO (1)
*Oct 18 09:22:37.471: TCP2: Telnet received DONT SUPPRESS-GA (3)
*Oct 18 09:22:37.471: TCP2: Telnet received WONT TTY-TYPE (24)
*Oct 18 09:22:37.471: TCP2: Telnet received WONT WINDOW-SIZE (31)
[Connection to 192.168.0.1 closed by foreign host]
R1#
*Oct 18 09:29:05.091: Telnet3: Sent SB 33 0
*Oct 18 09:29:05.095: Telnet0: recv SB 33 0


R1#sh run
Building configuration...
version 12.4
no service password-encryption
!
hostname R1
!
enable password cisco
!
username cisco password 0 cisco
!
interface FastEthernet0/0
 no ip address
 shutdown
 duplex half
!
interface Ethernet1/0
 ip address 192.168.0.1 255.255.255.0
 duplex half
!
interface Ethernet1/1
 no ip address
 duplex half
!
line vty 0 4
 login local
 transport input all
end



Comment
Watch Question

some oneNetwork Architect
CERTIFIED EXPERT
Top Expert 2014

Commented:
Change the variable "password" to something else, like "passwd" or "pwd" and try again. 

Author

Commented:
Thank you for your fast reply. I tried the way you mentioned, but it does not work.
However, I tried to type a wrong telnet password for example, password cisco is correct, but i typed cisco123, I still get the same message. That might mean logon to R1 never successfully 
some oneNetwork Architect
CERTIFIED EXPERT
Top Expert 2014

Commented:
Can you output a whole session from your Python window, please?

Author

Commented:
Please see the below. but not sure this is what you want to see. Thank you. 


some oneNetwork Architect
CERTIFIED EXPERT
Top Expert 2014

Commented:
Sorry, I mean as you are running the script.

Author

Commented:
Sorry, I am new to Python. I do not know where Python window that you mentioned is. My process for it is under NetworkAutomation-1, create nano file(paste above script and save) and then run it with python.

Author

Commented:
below is output with command show users at R1 connected to NetworkAutomation-1.
Line2 is connection of another router for test.
Line3 is connection of NetworkAutomation-1,


some oneNetwork Architect
CERTIFIED EXPERT
Top Expert 2014

Commented:
That's what I meant.. when you run it with Python can you show the output?

Anyway, I think I have sorted it for you. You may need to adjust the last line if you're running Py2 rather than Py3...

import getpass
import sys
import telnetlib

host  = '192.168.0.1'
user  = input('Enter username:')
password = getpass.getpass()
tn = telnetlib.Telnet(host)
tn.read_until(b'Username: ', 3)
tn.write(user.encode('ascii') + b'\n')
tn.read_until(b'Password: ', 3)  
tn.write(password.encode('ascii') + b'\n')
tn.write(('enable').encode('ascii') + b'\n')
tn.write(('cisco').encode('ascii') + b'\n')
tn.write(('conf t').encode('ascii') + b'\n')
tn.write(('int l0').encode('ascii') + b'\n')
tn.write(('ip add 1.1.1.1 255.255.255.255').encode('ascii') + b'\n')
tn.write(('end').encode('ascii') + b'\n')
tn.write(('exit').encode('ascii') + b'\n')
print(tn.read_all()) #use this instead if you run Python3
print tn.read_all()

Author

Commented:
please see below. and it cannot get debug message of telnet on R1

root@NetworkAutomation-1:~# python r1ee
Enter username:cisco
Traceback (most recent call last):
  File "r1ee", line 6, in <module>
    user  = input('Enter username:')
  File "<string>", line 1, in <module>
NameError: name 'cisco' is not defined
root@NetworkAutomation-1:~# cisco
bash: cisco: command not found
root@NetworkAutomation-1:~#

root@NetworkAutomation-1:~# cat r1ee
import getpass
import sys
import telnetlib

host  = '192.168.0.1'
user  = input('Enter username:')
password = getpass.getpass()
tn = telnetlib.Telnet(host)
tn.read_until(b'Username: ', 3)
tn.write(user.encode('ascii') + b'\n')
tn.read_until(b'Password: ', 3)
tn.write(password.encode('ascii') + b'\n')
tn.write(('enable').encode('ascii') + b'\n')
tn.write(('cisco').encode('ascii') + b'\n')
tn.write(('conf t').encode('ascii') + b'\n')
tn.write(('int l0').encode('ascii') + b'\n')
tn.write(('ip add 1.1.1.1 255.255.255.255').encode('ascii') + b'\n')
tn.write(('end').encode('ascii') + b'\n')
tn.write(('exit').encode('ascii') + b'\n')
print(tn.read_all()) #use this instead if you run Python3
print tn.read_all()



root@NetworkAutomation-1:~# python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /usr/lib/python2.7/site.pyc matches /usr/lib/python2.7/site.py
import site # precompiled from /usr/lib/python2.7/site.pyc
# /usr/lib/python2.7/os.pyc matches /usr/lib/python2.7/os.py
import os # precompiled from /usr/lib/python2.7/os.pyc
import errno # builtin
import posix # builtin
# /usr/lib/python2.7/posixpath.pyc matches /usr/lib/python2.7/posixpath.py
import posixpath # precompiled from /usr/lib/python2.7/posixpath.pyc
# /usr/lib/python2.7/stat.pyc matches /usr/lib/python2.7/stat.py
import stat # precompiled from /usr/lib/python2.7/stat.pyc
# /usr/lib/python2.7/genericpath.pyc matches /usr/lib/python2.7/genericpath.py
import genericpath # precompiled from /usr/lib/python2.7/genericpath.pyc
# /usr/lib/python2.7/warnings.pyc matches /usr/lib/python2.7/warnings.py
import warnings # precompiled from /usr/lib/python2.7/warnings.pyc
# /usr/lib/python2.7/linecache.pyc matches /usr/lib/python2.7/linecache.py
import linecache # precompiled from /usr/lib/python2.7/linecache.pyc
# /usr/lib/python2.7/types.pyc matches /usr/lib/python2.7/types.py
import types # precompiled from /usr/lib/python2.7/types.pyc
# /usr/lib/python2.7/UserDict.pyc matches /usr/lib/python2.7/UserDict.py
import UserDict # precompiled from /usr/lib/python2.7/UserDict.pyc
# /usr/lib/python2.7/_abcoll.pyc matches /usr/lib/python2.7/_abcoll.py
import _abcoll # precompiled from /usr/lib/python2.7/_abcoll.pyc
# /usr/lib/python2.7/abc.pyc matches /usr/lib/python2.7/abc.py
import abc # precompiled from /usr/lib/python2.7/abc.pyc
# /usr/lib/python2.7/_weakrefset.pyc matches /usr/lib/python2.7/_weakrefset.py
import _weakrefset # precompiled from /usr/lib/python2.7/_weakrefset.pyc
import _weakref # builtin
# /usr/lib/python2.7/copy_reg.pyc matches /usr/lib/python2.7/copy_reg.py
import copy_reg # precompiled from /usr/lib/python2.7/copy_reg.pyc
# /usr/lib/python2.7/traceback.pyc matches /usr/lib/python2.7/traceback.py
import traceback # precompiled from /usr/lib/python2.7/traceback.pyc
# /usr/lib/python2.7/sysconfig.pyc matches /usr/lib/python2.7/sysconfig.py
import sysconfig # precompiled from /usr/lib/python2.7/sysconfig.pyc
# /usr/lib/python2.7/re.pyc matches /usr/lib/python2.7/re.py
import re # precompiled from /usr/lib/python2.7/re.pyc
# /usr/lib/python2.7/sre_compile.pyc matches /usr/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/lib/python2.7/sre_parse.pyc matches /usr/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/lib/python2.7/sre_parse.pyc
# /usr/lib/python2.7/sre_constants.pyc matches /usr/lib/python2.7/sre_constants.py
import sre_constants # precompiled from /usr/lib/python2.7/sre_constants.pyc
import _locale # builtin
# /usr/lib/python2.7/_sysconfigdata.pyc matches /usr/lib/python2.7/_sysconfigdata.py
import _sysconfigdata # precompiled from /usr/lib/python2.7/_sysconfigdata.pyc
# /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.pyc matches /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.py
import _sysconfigdata_nd # precompiled from /usr/lib/python2.7/plat-x86_64-linux-gnu/_sysconfigdata_nd.pyc
# /usr/lib/python2.7/sitecustomize.pyc matches /usr/lib/python2.7/sitecustomize.py
import sitecustomize # precompiled from /usr/lib/python2.7/sitecustomize.pyc
import encodings # directory /usr/lib/python2.7/encodings
# /usr/lib/python2.7/encodings/__init__.pyc matches /usr/lib/python2.7/encodings/__init__.py
import encodings # precompiled from /usr/lib/python2.7/encodings/__init__.pyc
# /usr/lib/python2.7/codecs.pyc matches /usr/lib/python2.7/codecs.py
import codecs # precompiled from /usr/lib/python2.7/codecs.pyc
import _codecs # builtin
# /usr/lib/python2.7/encodings/aliases.pyc matches /usr/lib/python2.7/encodings/aliases.py
import encodings.aliases # precompiled from /usr/lib/python2.7/encodings/aliases.pyc
# /usr/lib/python2.7/encodings/ascii.pyc matches /usr/lib/python2.7/encodings/ascii.py
import encodings.ascii # precompiled from /usr/lib/python2.7/encodings/ascii.pyc
Python 2.7.17 (default, Apr 15 2020, 17:20:14)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/usr/lib/python2.7/lib-dynload/readline.x86_64-linux-gnu.so", 2);
import readline # dynamically loaded from /usr/lib/python2.7/lib-dynload/readline.x86_64-linux-gnu.so
>>>




Network Architect
CERTIFIED EXPERT
Top Expert 2014
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
Great, Thank you!

Author

Commented:
Hi some one,
the previous script that I used is different with yours. yours has ('ascii') etc. Why do you use different one? its different version? thanks

here was one i used:
import getpass
import sys
import telnetlib

HOST = "192.168.0.1"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("username:  ")
tn.write(user + "\n")
if password:
    tn.read_until("Password:  ")
    tn.write(password + "\n")

tn.write("enable\n")
tn.write("cisco\n")
tn.write("config t\n")
tn.write("interface loop 0\n")
tn.write("ip address 1.1.1.1 255.255.255.255\n")
tn.write("end\n")
tn.write("exit\n")
print tn.read_all()
some oneNetwork Architect
CERTIFIED EXPERT
Top Expert 2014

Commented:
Mine was using Py3. The reason I used ascii encoding was because some docs mention that if you don't encode in ascii the device may not see the complete string you send. That was the case for me when I tried your code.