代码拉取完成,页面将自动刷新
同步操作将从 cutecuteyu/qytang_Python 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#!/usr/bin/python3
from telnetlib import Telnet
import re
import time
def copyips(username, password, rackno, verno):
ipssig = re.compile(r'^service interface.*')
if rackno == 'BJRack01':
rackip = '172.17.100.111'
elif rackno == 'BJRack02':
rackip = '172.17.100.112'
elif rackno == 'BJRack03':
rackip = '172.17.100.113'
portno = 2017
tn = Telnet(rackip, portno)
tn.write(b'\r\n')
tn.read_very_eager()
time.sleep(1)
tn.write(b'\r\n')
tn.read_very_eager()
time.sleep(1)
tn.write(b'\r\n')
tn.read_very_eager()
time.sleep(1)
tn.write(b'\n')
tn.write(b'\n')
time.sleep(1)
tn.write(b'cisco\n')
time.sleep(2)
tn.write(b'123cisco123\n')
tn.write(b'\n\n\n')
time.sleep(1)
tn.write(b'end\n\n')
time.sleep(1)
tn.write(b'end\n\n')
time.sleep(1)
tn.write(b'terminal length 0\n\n')
time.sleep(1)
tn.write(b'terminal length 0\n\n')
time.sleep(1)
rackreply = tn.expect([],timeout=1)[2].decode().strip()
tn.write(b'show configuration\n\n')
rackreplyipst = tn.expect([],timeout=60)[2].decode().strip()
# print(rackreplyipst)
configfiletmp = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'IPST' + '.txt'
configtmp = open(configfiletmp, 'w')
configtmp.write(rackreplyipst)
configtmp.close
time.sleep(1)
configtmp = open(configfiletmp, 'r')
# print(configtmpr)
# configtmptest = open(configfiletmp, 'r').read()
# print(configtmptest)
rackreplylines = configtmp.readlines()
# print(rackreplylines)
rackreplylinesnew = []
for line in rackreplylines:
if line == '\n':
pass
else:
rackreplylinesnew.append(line)
location = 1
i = 1
for line in rackreplylinesnew:
i = i + 1
if ipssig.match(line.strip()):
location = i - 2
print(location)
ipsconfiglst = rackreplylinesnew[location:]
ipsconfig = ''.join(str(e) for e in ipsconfiglst)
configfile = '/python/cgi-bin/tmpconfig/' + verno + '/' + 'IPS' + '.txt'
config = open(configfile, 'w')
config.write(ipsconfig)
config.close()
tn.close()
if __name__ == "__main__":
copyips('labtest', 'Cisc0123', 'BJRack03', 'v12')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。