import re
import os
import openpyxl
from openpyxl import Workbook,workbook
from concurrent.futures import ThreadPoolExecutor
import time class xshell_session: def __init__(self,excel_name):
self.excel_name = excel_name
self.all_row_dic = [] # 存储列表所有字典
with open("tmp.xsh", "r", encoding="utf-16-le") as tmp:
self.tmp_file = tmp.read()
try:
os.mkdir("./session")
except:
pass
def get_ip_list(self):
wb = openpyxl.load_workbook(filename=self.excel_name) #type:workbook.Workbook
sheet_info = wb[wb.sheetnames[0]] # 进入当前工作sheet
max_colum = sheet_info.max_column
max_row = sheet_info.max_row
row_data = list(sheet_info.rows) #遍历行数据
header = [] # 创建空列表存储key值
for data in range(1,max_colum+1):
get_header = sheet_info.cell(row=1,column=data).value
header.append(get_header)
#print(header)
for row in row_data:
reslut = [] # 创建列表,存储每行的数据
for i in row:
reslut.append(i.value)
row_dic = dict(zip(header,reslut))
#print(row_dic)
self.all_row_dic.append(row_dic)
self.all_row_dic.pop(0)
print(self.all_row_dic)
for i in self.all_row_dic:
print(i)
def creat_session_file(self):
os.chdir("./session")
for i in self.all_row_dic:
ip = i["IP"]
dev_name = i["name"]
#print(dev_name)
#print(ip)
new_file = dev_name+".xsh"
session = re.sub("Host=.*", "Host=" + ip, self.tmp_file)
with open(new_file,"w",encoding="utf-8") as file:
file.write(session)
print(new_file) session = xshell_session("iplist.xlsx")
session.get_ip_list()
session.creat_session_file()

最新文章

  1. python基础补漏-03-函数
  2. CodeForces - 453A Little Pony and Expected Maximum
  3. PHPStorm技巧篇 -- 全局搜索
  4. JQ写下拉列表项目移动(内附效果图和源代码)
  5. JAVA笛卡尔曲线
  6. jquery知识 属性 css
  7. url、base64 编码规则
  8. Qt for Android 部署流程分析
  9. 使用GDAL图书馆RPC校正问题
  10. Chromium Graphics: GPUclient的原理和实现分析之间的同步机制-Part I
  11. HDU 2037 今年暑假不AC(贪心)
  12. Codefoces 723B Text Document Analysis
  13. 微信小程序支付遇到的坑
  14. 基于centOS7:新手篇→tomcat的部署方式
  15. 【学习笔记】Tensorflow+Inception-v3训练自己的数据
  16. Javascript非构造函数的继承
  17. Ubuntu SVN安装&使用&命令
  18. js判断各种浏览器
  19. Vue学习记录-初探Vue
  20. javascript进阶修炼之一——javascript必备操做

热门文章

  1. Crossplane - 比 Terraform 更先进的云基础架构管理平台?
  2. Monkey 命令
  3. FAQ 关于allure和pycharm的运行模式
  4. Rust 的PIN的作用图
  5. mysql13 sql优化-explain
  6. echarts入门到应用学习笔记
  7. PX4源码地址和wiki
  8. 安卓逆向 ARM基础篇
  9. 浅显直白的Python深拷贝与浅拷贝区别说明
  10. 网页实时显示已经运行了多少天 html+js