可乐博客

Python获取SQLYOG账号密码


import os
import configparser
import base64


def decode(base64str):
    tmp = base64.b64decode(base64str)
    return bytearray([(b<<1&255)|(b>>7) for b in tmp]).decode("utf8")

sqlyogini = os.environ.get('APPDATA')+"\\SQLyog\\sqlyog.ini"
# sqlyogini = "C:\\Kele\\Cache\\python_test\\syslogini\\sqlyog.ini"

ini = configparser.ConfigParser()
# ini.read(sqlyogini,encoding='utf8')
ini.read_string(open(sqlyogini, encoding='utf8').read().replace('[]',''))

connections = [r for r in ini.sections() if 'name' in ini.options(r) and ini.get(r,'password')]

for c in connections:
    name = ini.get(c,'name').strip()
    host = ini.get(c,'host')
    user = ini.get(c,'user')
    b64pass = ini.get(c,'password')
    password = decode(b64pass)

    print(name,host,user,password,sep='\t')
    print('-'*100)
技术