python实现linux服务器批量修改密码并生成execl
发布时间:2022-11-22 17:16:06
批量修改linux服务器密码,同时生成execl表格
#!/usr/bin/env python
#coding:utf8
#随机生成自定义长度密码
from random import choice
import string,pickle
def GenPassword(length=8,chars=string.ascii_letters+string.digits):
return ''.join([choice(chars) for i in range(length)])
def passlist(r_user,c_user,ip_list,web_list):
dic={}
for i in ip_list:
if i.split()[1] in web_list:
dic[i.split()[1]]=[i.split()[0],{r_user:GenPassword(32),c_user:GenPassword(32)}]
else:
dic[i.split()[1]]=[i.split()[0],{r_user:GenPassword(32)}]
return dic
def ip_list(ip_file):
with open(ip_file) as file:
ip_file=file.read().strip().split("\n")
#web_list=[i for i in ip_file if i in web_list]
return ip_file
def save_dic():
dic=main()
with open("../host_message.pickle","w") as fd:
pickle.dump(dic,fd)
def main():
file="/root/cui/script/python/ip.txt"
web_list=[ip1,ip2,ip3,ip4]
file_list=ip_list(file)
file_dic_pass=passlist("root","www",file_list,web_list)
return file_dic_pass
if __name__=="__main__":
save_dic()
#!/usr/bin/env python
#coding:utf8
#批量修改密码主程序
import pickle
from ssh_co.ssh_connect import sshd
from command.ip_passwd import save_dic,main
from execl import set_execl
def read_dic():
with open("host_message.pickle","rb") as f:
return pickle.load(f)
def ssh_main():
pid_host=1
host_message=read_dic()
host_list=host_message.keys()
print host_list
for host_msg in xrange(len(host_list)):
host_attribute=(host_list[host_msg],port,user,passwd)
ssh_conn=sshd(host_attribute,pid_host)
if "www" in host_message[host_list[host_msg]][1].keys():
for username in xrange(len(host_message[host_list[host_msg]][1].keys())):
try:
user=host_message[host_list[host_msg]][1].keys()[username]
passwd=host_message[host_list[host_msg]][1][host_message[host_list[host_msg]][1].keys()[username]]
results=ssh_conn.set_ssh_cmd(u"/bin/echo %s|/usr/bin/passwd --stdin %s" %(passwd,user))
print results,host_list[host_msg],user+"-----------"+passwd
except:
print results,host_list[host_msg],user+"-----except------"+passwd
else:
user=host_message[host_list[host_msg]][1].keys()[0]
passwd=host_message[host_list[host_msg]][1][host_message[host_list[host_msg]][1].keys()[0]]
result=ssh_conn.set_ssh_cmd(u"/bin/echo %s|/usr/bin/passwd --stdin %s" %(passwd,user))
print result,host_list[host_msg],user+"-----------"+passwd
if __name__ == "__main__":
dic=main()
with open("host_message.pickle","w") as fd:
pickle.dump(dic,fd)
set_execl()
ssh_main()
![](https://www.aspxhome.com/images/zang.png)
![](https://www.aspxhome.com/images/jiucuo.png)
猜你喜欢
- 在本篇文章当中主要给大家深入介绍在 cpython 当中非常重要的一个数据结构 code object! 在上一篇文章 深入理解 pytho
- 举几个例子来介绍一下,Python 的 CSV模块的使用方法,包括,reader, writer, DictReader, DictWrit
- 1.在pycharm中新建project demo1 添加app01 点击create按钮完成新建2.在demo项目目录下新建目录stati
- 1.索引碎片的产生?由于在表里大量的插入、修改、删除操作而使索引页分裂。如果索引有了高的碎片,有两种情况,一种情况是扫描索引需要花费很多的时
- title: 利用Django实现一个能与用户交互的初级框架author: Sun-Winddate: September 1, 2021D
- 理解property和attribute这个要看具体的语境了。不过我们可以从词源的角度来区分一下这两者:property形容词propert
- HTTP-REFERER这个变量已经越来越不可靠了,完全就是可以伪造出来的东东。 以下是伪造方法:ASP/Visual Basic代码 di
- 1.乘法和幂运算符● 单个 * 用于乘法运算● 两个 ** 表示幂运算>>> 2*3>>> 6>&
- 1. 停止服务MySQL2. 卸载mysql相关的程序3. 删除注册表(运行->regedit),machine->system
- 本文实例为大家分享了python静态服务器的具体代码,供大家参考,具体内容如下#coding:utf-8import socketimpor
- 在Jupyter Notebook上使用Python+opencv实现如下图像缺陷检测。关于opencv库的安装可以参考:Python下op
- GetObject 函数返回对文件中 Automation 对象的引用。GetObject([pathname] [, class])参数P
- 背景写一个python脚本,实现简单的http服务器功能:1.浏览器中输入网站地址:172.20.52.163:200142.server接
- watch介绍vue中watch用来监听数据的响应式变化.获取数据变化前后的值watch的完整入参watch(监听的数据,副作用函数,配置对
- 关于 Go 中 Map 类型和 Slice 类型的传递Map 类型先看例子 m1:func main() { m := make
- FTP即文件传输协议;它基于客户机-服务器模型体系结构,应用广泛。它有两个通道:一个命令通道和一个数据通道。命令通道用于控制通信,数据通道用
- 原始值->基本类型Number String Boolean undefined null存储在栈(stack)中的简单数据段,也就是
- Go语言实现互斥锁、随机数、time、Listimport ( "container/list"  
- 从毕业实习算起,从事可用性方面的工作到现在已经5年了。在此记录笔者的一些所见所想,和大家讨论分享一下。用户研究在“以用户为中心”的界面设计方
- 1、数组a第0个元素(二维数组)下的所有子元素(一维数组)的第一列import numpy as npb=np.arange(24)a=b.