fr2w 发表于 2015-1-28 08:38:47

使用python编写ssh工具

#!/usr/bin/env python
import os
ip_file = '/home/sean/ip.txt'
f = file(ip_file)
ip_dic = {}
num = 0
while True:
      line = f.readline()
      if len(line) == 0:break
      num +=1
      ip_dic = line
f.close()
for a,b in ip_dic.items():
      print '\033[32;1m%s. %s\033[0m'%(a,b),
option = int(raw_input('please choose one server to connect:'))
if option in ip_dic.keys():
      print ip_dic,
      user = raw_input('username:').strip()
      cmd = 'ssh %s@%s' %(user,ip_dic)
      os.system(cmd)
else:
      print 'Input error!'
页: [1]
查看完整版本: 使用python编写ssh工具