Python paramiko 简单应用-分析Linux上的文本信息

import paramiko,os,time

#!/usr/bin/env python

#Please modify server_info with your XMS info
server_info = {
    'hostname': '172.16.83.60',
    'port':'22',
    'username': 'root',
    'passwd':'2@WSX3edc'
}
result = {}

def install_paramiko(wait_time = 120):
        while True:
            prompt_input = input('paramiko is a python module. It is not installed by default. Hv paramiko installed before(Y/N)?')
            if prompt_input=='N':
                os.system('pip install paramiko')
                print('please wait 120 second for paramiko to be installed')
                time.sleep(wait_time)
                break
            elif prompt_input =='Y':
                break
            else:
                print('Dear, This script need paramiko installed')

def analyze_conn(lines):
    for line in lines:
        if line.startswith("pooled.datasource.url="):
            result["pooled.datasource.url"] = line
            if "jdbc:jtds:sqlserver" in line:
                result["driver type"] = "JDTS"
                if "useNTLMv2=true" in line:
                    result["Authentication"] = "Windows Authentication"
                else:
                    result["Authentication"] = "SQL Authentication"
                if "ssl=off" in line:
                    result["SSL"] = "Off"
                else:
                    result["SSL"] = "On"
            else:
                result["driver type"] = "JDBC"
                if "authenticationScheme" in line:
                    result["Authentication"] = "Windows Authentication"
                else:
                    result["Authentication"] = "SQL Authentication"
                if "encrypt=true" in line:
                    result["SSL"] = "On"
                else:
                    result["SSL"] = "Off"
            return result
    print(result)
    return result

install_paramiko()

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(server_info['hostname'], server_info['port'], server_info['username'], server_info['passwd'])
stdin, stdout, stderr = ssh.exec_command('cat /opt/sas/sw/tomcat/inst1/webapps/ROOT/WEB-INF/classes/ew-config.properties')
ew_text = stdout.read().decode()

f_save = open(".temp.txt", 'w+')
print(ew_text, file=f_save)

f_open = open('.temp.txt')
analyze_conn(f_open)

print("Driver Type          : {0}".format(result["driver type"]))
print ("Authentication       : {0}".format(result["Authentication"]))
print ("SSL                  : {0}".format(result["SSL"]))
print ("pooled.datasource.url: {0}".format(result["pooled.datasource.url"]))

ssh.close()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值