1 import paramiko,os,sys
2
3
4 host_dic = { "10.10.154.77":"s1",
5 "10.10.83.96":"s2",
6 "10.10.39.70":"s3",
7 "10.10.46.120":"s4",
8 "10.10.15.128":"s5",
9 "10.10.84.48":"s6",
10 "10.10.123.96":"s7",
11 "10.10.172.89":"s8",
12 "10.10.230.51":"s9",
13 "10.10.105.91":"qa1",
14 "10.10.92.48":"qa2",
15 "10.10.50.30":"qa3",
16 "10.10.40.136":"qa4",
17 "10.10.189.139":"qa5",
18 "10.10.192.192":"xjgqa1",
19 "10.10.199.12": "xjgqa2",
20
21 "10.10.96.194":"uat1",
22 "10.10.159.36":"uat2",
23 "10.10.157.177":"uat3",
24 "10.10.233.82":"uat4",
25 "10.10.180.81":"uat5",
26 "10.10.179.51":"xjguat1",
27
28 "10.10.72.83":"sit1",
29 "10.10.88.122": "sit2",
30 "10.10.52.135": "sit3",
31 "10.10.13.142": "sit4",
32 "10.10.178.156": "sit5",
33 "10.10.185.166": "xjgsit1",
34 }
35
36 cmd = "passwd oracle"
37 password = "B^Dc%4LSBvhZZK3B"
38
39 pwd = "tdNQyl*e2H\n"
40 def ssh_cmd(ip,port,cmd,user,passwd):
41
42 ssh = paramiko.SSHClient()
43 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
44 ssh.connect(ip,port,user,passwd)
45 stdin, stdout, stderr = ssh.exec_command(cmd)
46 stdin.write(pwd)
47 stdin.flush()
48 stdin.write(pwd)
49 stdin.flush()
50 result = stdout.read()
51 error = stderr.read()
52 #print ("out:",result)
53 #print("error:",error)
54 if "successfully" in result.decode():
55 print("%s 密码修改成功 "%host_dic.get(ip))
56 else:
57 print("%s 密码修改失败 "%host_dic.get(ip))
58 ssh.close()
59
60
61 # ssh_cmd(ip,22,cmd,"root",password)
62
63 for i in host_dic.keys():
64 ssh_cmd(i, 22, cmd, "root", password)