Je n'arrive pas à faire fonctionner le script suivant, même dans le cas où la connexion est réussie ou lorsque la connexion échoue.Telnet vers plusieurs routeurs Cisco utilisant le script Python
Quelles expressions régulières puis-je utiliser pour accepter toutes les invites ci-dessous?
router1>; router3>; router4#
Comment puis-je utiliser une expression régulière où je peux attendre tout le texte avant « échec » et après l'autorisation « échec » rapide et puis à la fin, je vais me > > > "refusé
Current failed Login: ########
User Access Verification
Username: asdsad
Password:
% Authentication failed
Current Successful Login ###########
[[email protected] testuserpass]# telnet 192.168.1.31
Trying 192.168.1.31...
Connected to 192.168.1.31.
Escape character is '^]'.
User Access Verification
Username: admin
Password:
testname>
testname>
testname>
testname>
testname>
Mon script ci-dessous ################
question identification telnet routeurs Cisco Regular expressions
#! /usr/bin/python
import pexpect
import getpass
HOST = "192.168.1.31"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()
child = pexpect.spawn ('telnet '+HOST)
child.expect ('Username: ')
child.sendline (user)
child.expect ('Password: ')
child.sendline (password)
//// ######I just can't get below part to work.
i = child.expect (['*Authentication*', 'Terminal type', '[#\$>] '])
if i==0:
print('Permission denied on host. Can\'t login')
child.kill(0)
print child.readline()
elif i==1:
print('Login OK... need to send terminal type.')
child.sendline('vt100')
child.expect('[#\$] ')
print child.readline()
elif i==2:
print('Login OK.')
print('Shell command prompt', child.after)
print child.readline()