#!/usr/bin/python
import sys
import time
import os
import pexpect
now = time.strftime('%Y-%m-%d',time.localtime(time.time()))
aa = open ('/home/hanlei/test/%s/log.txt' % now, "w")
fout = open ('/home/hanlei/test/%s/log.txt' % now, "w")
IP = open('/home/hanlei/test/switch_ip','r')
PASS = open('/home/hanlei/test/switch_passwd','r')
while 1:
READIP = IP.readline()
READPASS = PASS.readline()
if not READIP:
print 'END'
break
foo = pexpect.spawn('telnet %s' % READIP)
foo.log_file = fout
foo.expect(['Username:'])
foo.sendline('admin')
foo.expect(['Password:'])
foo.sendline('admin')
foo.expect(['>'])
foo.sendline('en')
foo.expect(['Password:'])
foo.sendline(READPASS)
foo.expect(['#'])
foo.sendline('copy flash:config.text scp:')
foo.expect(['Address or name of remote host'])
foo.sendline('192.168.1.141') #FTP SERVER
foo.expect(['Destination username'])
foo.sendline('cisco')
foo.expect(['config.text'])
foo.sendline('t1206')
foo.expect(['Password:'])
foo.sendline('123456')
a = foo.expect (['bytes/sec', 'Error', pexpect.EOF, pexpect.TIMEOUT])
if a == 0:
aa.write('%s......ok ' % READIP)
foo.expect(['#'])
foo.sendline('quit')
if a == 1:
aa.write('%s......failed ' % READIP)
foo.sendline('quit')
foo.expect(['closed'])
foo.interact
print 'done'
python 抓取cisco交换机配置文件
免责声明:文章转载自《python 抓取cisco交换机配置文件》仅用于学习参考。如对内容有疑问,请及时联系本站处理。
宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=