Repository navigation
Expand file tree
/
Copy pathchagepsd.py
More file actions
40 lines (36 loc) · 1.45 KB
/
Copy pathchagepsd.py
File metadata and controls
40 lines (36 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import paramiko
import socket
def connect_demo(IP,user,old_password,new_password):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(hostname=IP, port=22, username=user, password=old_password,timeout=5)
command = "passwd %s" %(user)
stdin, stdout, stderr = ssh.exec_command(command)
stdin.write(old_password + '\n')
stdin.write(new_password + '\n' + new_password + '\n')
out, err = stdout.read(), stderr.read()
successful = 'password updated successfully'
if successful in str(err):
print(IP+" :password has been changed")
else:
print(str(err))
ssh.close()
except paramiko.ssh_exception.AuthenticationException as e:
print(IP + ' ' + "dont need change")
except socket.timeout as e:
print(IP+"connect timeout")
IPaddress = ['172.16.0.7','172.16.0.202','172.16.0.100','172.16.0.140']
for i in range(len(IPaddress)):
IP = IPaddress[i]
connect_demo(IP,"ubuntu","openstack","chtMBFTQx8")
# def main():
# IPaddress = ['172.16.0.7','172.16.0.202','172.16.0.100','172.16.0.140']
# for i in range(len(IPaddress)):
# IP = IPaddress[i]
# user = "ubuntu"
# old_password = "openstack"
# new_password = ""
# connect_demo(IP,user,old_password,new_password)
# if __name__ == "__main__":
# main()