• python 抓取cisco交换机配置文件


    #!/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'

  • 相关阅读:
    领料单取整
    财务应付金额对不上的
    销售订单计算交期
    辅助单位启用
    K3CLOUD日志目录
    QLIKVIEW-日期格式,数字格式写法
    MRP运算报错-清除预留
    整单折扣后 财务、暂估应付价税合计对不上的问题处理
    BZOJ 2976: [Poi2002]出圈游戏 Excrt+set
    BZOJ 3060: [Poi2012]Tour de Byteotia 并查集
  • 原文地址:https://www.cnblogs.com/han1094/p/7994223.html
Copyright © 2020-2023  润新知