출력의 값 내가 OUTSIDEMAP 후 숫자 값을 잡기 위해 필요파이썬 - 잡아 내 .send에서 paramiko 모듈에 파이썬 스크립트를 실행하고 있고 내가이 출력을 가지고 .recv
crypto map OUTSIDEMAP 10 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 20 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 21 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 23 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 25 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 26 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 27 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 430 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 550 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 660 match address XXXXXXXXXXX
crypto map OUTSIDEMAP 800 match address XXXXXXXXXXX
(10 , 20, 21 등). 분할 방식을 시도했지만 표시되는 행 수가 언제든지 변경 될 수 있으므로 목록 값 위치를 수정하지 않아도됩니다.
아이디어가 있으십니까? 코드
#!/usr/bin/env python
import paramiko
import time
# Variables
host = xxxxxx = 'xxxxxx'
# Create instance of SSHClient object
ssh = paramiko.SSHClient()
# Automatically add untrusted hosts
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# Automatically add untrusted hosts
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# initiate SSH connection
ssh.connect('xxxxxx', port=22, username='xxxxx', password='xxxxx', look_for_keys=False, allow_agent=False)
print "SSH COnnection established with %s" % host
# Use invoke_shell to establish an 'interactive session'
ssh_conn = ssh.invoke_shell()
print "Interactive SSH session established"
print "Give the name of the 3PPartner\n"
partner = raw_input('>')
# Commands prompted
ssh_conn.send('\n')
ssh_conn.send('enable\n')
time.sleep(.5)
ssh_conn.send('xxxxxxxn')
time.sleep(.5)
ssh_conn.send("terminal pager 0\n")
time.sleep(.5)
ssh_conn.send('show running-config crypto map | i ' + str(partner) + '\n')
time.sleep(1)
output = ssh_conn.recv(65535)
# Edit output
c_map = output.split(' ')
print c_map[25]
print c_map[31]
print c_map[37]
# Close session
ssh.close()
print 'Logged out of device %s' %host
왜 정규식을 피하려고합니까? – voiDnyx
잊어 버려. 정규식으로 가기도 행복 –