python 批量修改密码

简介:

下午闲来无事,就搞个批量密码修改工具玩玩...

#!/usr/bin/env python
import paramiko
import time

ip_list=('ip1','ip2')
log_file=open('mpwdok.log','w+')
log_file1=open('mpwderr.log','w+')

for ip in ip_list:
    try:
        s = paramiko.Transport((ip, 22))
        s.connect(username='root', password='222222')
        chan = s.open_session()
        chan.get_pty()
        chan.invoke_shell()
        chan.send('passwd root\n')
        time.sleep(2)
        chan.send('111111\n')
        time.sleep(2)
        chan.send('111111\n')
        time.sleep(2)
        log_file.write("\n"+ip+"\n=================================================================\n")
        log_file.write(chan.recv(1024))
        log_file.write("\n=================================================================")
    except Exception,err:
        log_file1.write("ERR:unable to connect %s:%s\n" %(ip,err))

 

以下是另一种方式自动登录并且修改密码的脚本,仅供参考:

#!/usr/bin/env python
#CreateBy:Badboy 2010-11-02
#Auto modify user passwd

import paramiko
import time
import ConfigParser

cf=ConfigParser.ConfigParser()
cf.read("userinfo.conf")
userName=cf.get("user_info","user_name")
userPass=cf.get("user_info","user_pwd")
serverPort=cf.getint("user_info","server_port")
keyFile=cf.get("user_info","key_path")
ip_list=cf.get("user_info","ip_list").split(",")

channel = paramiko.SSHClient();
channel.set_missing_host_key_policy(paramiko.AutoAddPolicy())
log_file=open('mpwdok.log','w+')
log_file1=open('mpwderr.log','w+')

for serverHost in ip_list:
    try:
        mpwdssh=paramiko.Transport((serverHost,serverPort))
        mykey = paramiko.DSSKey.from_private_key_file(keyFile,password=userPass)
        mpwdssh.connect(username=userName,pkey=mykey)
        chan = mpwdssh.open_session()
        chan.get_pty()
        chan.invoke_shell()
        chan.send('passwd root\n')
        time.sleep(2)
        chan.send('222222\n')
        time.sleep(2)
        chan.send('222222\n')
        time.sleep(2)
        log_file.write("\nLinuxServer_IP:"+serverHost+"\n=================================================================\n")
        log_file.write(chan.recv(1024))
        log_file.write("\n=================================================================")
    except Exception,err:
        log_file1.write("ERR:unable to connect %s:%s\n" %(serverHost,err))
 

userinfo.conf

[user_info]
user_name=root
user_pwd=111111
server_port=22
key_path=/root/.ssh/badboy
ip_list=ip1,ip2



本文转自hahazhu0634 51CTO博客,原文链接:http://blog.51cto.com/5ydycm/407163,如需转载请自行联系原作者

相关文章
|
4月前
|
数据安全/隐私保护 Python
1178: 密码翻译(python)
1178: 密码翻译(python)
|
4月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:0~4
Python 密码破解指南:0~4
211 0
Python 密码破解指南:0~4
|
4月前
|
存储 算法 安全
Python 密码破解指南:20~24
Python 密码破解指南:20~24
166 0
|
4月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:15~19
Python 密码破解指南:15~19
233 0
|
4月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:10~14
Python 密码破解指南:10~14
200 0
|
4月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:5~9
Python 密码破解指南:5~9
134 0
|
4天前
|
安全 数据安全/隐私保护 Python
情书也能加密?Python AES&RSA,让每一份数据都充满爱的密码
【9月更文挑战第8天】在这个数字化时代,情书不再局限于纸笔,也可能以电子形式在网络中传递。为了确保其安全,Python提供了AES和RSA等加密工具,为情书编织爱的密码。首先,通过安装pycryptodome库,我们可以利用AES对称加密算法高效保护数据;接着,使用RSA非对称加密算法加密AES密钥和IV,进一步增强安全性。即使情书被截获,没有正确密钥也无法解读内容。让我们用Python为爱情编织一张安全的网,守护每份珍贵情感。
17 2
|
27天前
|
数据安全/隐私保护 Python
Python 解压还密码的压缩文件 LookupError: Couldn't find path to unrar library.
Python 解压还密码的压缩文件 LookupError: Couldn't find path to unrar library.
37 2
|
1月前
|
安全 数据安全/隐私保护 Python
【Leetcode刷题Python】密码校验
文章提供了一个Python程序,用于验证密码是否符合特定的安全标准,包括密码长度至少为6,数字字符个数少于字母字符个数,没有连续5个字符是字母,以及没有连续两个字符是一模一样的,并输出每个密码是否符合这些条件。
21 3
|
1月前
|
安全 数据安全/隐私保护 Python