首页 > 代码库 > python 跳板机日志审计系统

python 跳板机日志审计系统

下载安装Ajaxterm

创建一个新用户

这里我建了一个ip.txt文件存放ip地址

su - HaojieMao

vi term__ssh.py

代码如下:

  

#! /usr/bin/env python
import os

ip_file = ‘ip.txt‘
ip_dic = {}
num = 0
f = file(ip_file)
while True:
        num += 1
        line = f.readline()
        if len(line) == 0:break
        ip_dic[num] = line
f.close()
while True:
  try:
        for k,v in ip_dic.items():
                print "%s. %s"%(k,v)
        option = int(raw_input(‘Please choose one server to connect:‘))
        if option in ip_dic.keys():
                print ip_dic[option]
                f = file(log_file,‘a‘)
                f.write("\n-------LOGIN INFO: connect to %s\n"%ip_dic[option])
                f.close()
                user = raw_input(‘username:‘).strip()
                cmd = ‘ssh %s@%s‘ % (user,ip_dic[option])
                os.system(cmd)
        else:
                print‘Number out of range!‘
  except ValueError:
        print ‘Wrong‘

  

 

python 跳板机日志审计系统