欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3讀取MySQL-Front的MYSQL密碼

 更新時(shí)間:2017年05月03日 08:36:16   作者:codegay  
本篇文章主要介紹了python3讀取MySQL-Front的MYSQL密碼的相關(guān)知識,具有很好的參考價(jià)值。下面跟著小編一起來看下吧

前言

同樣的套路又來了,繼續(xù)嘗試從配置文件中讀取敏感的信息,這次輪到的是MySQL-Front

MySQL-Front就一款開源的mysql管理工具,官方網(wǎng)站http://www.mysqlfront.de/ 。

配置文件的路徑:

MySQL-Front的配置文件存在用戶目錄下,環(huán)境變量是%appdata% 。

在windows7下的存儲路徑是:

C:\Users\%user%\AppData\Roaming\MySQL-Front\Accounts.xml

Accounts.xml這個(gè)XML文件里面存儲了所有重要的信息,且密碼默認(rèn)不是加密的。上次我忘記mysql root用戶的密碼,打開這個(gè)文件立馬就找回密碼,

這個(gè)算是不加密的好處吧?!鷂→不過總有刁民想害朕,還是需要保護(hù)好這些重要的信息,以免被壞人讀取到。

格式化XML

Accounts.xml 中的內(nèi)容是被壓縮成一行的。需要格式化成好看的格式。這類在線工具搜索一下就可以找得到。

Accounts.xml 格式化后的內(nèi)容如下:

<?xml version="1.0" encoding="utf-8"?>
<accounts version="1.1.0">
 <default>127.0.0.1</default>
 <account name="127.0.0.1">
 <lastlogin>42847.9391816088</lastlogin>
 <manualurl version="5.0.22-community-nt"></manualurl>
 <connection>
  <database></database>
  <host>127.0.0.1</host>
  <library>
  <filename>libMySQL.dll</filename>
  <tunnel_url></tunnel_url>
  </library>
  <password encode="none">root</password>
  <port>3306</port>
  <user>root</user>
 </connection>
 <favorites />
 </account>
 <account name="daqin">
 <lastlogin>0</lastlogin>
 <manualurl version=""></manualurl>
 <connection>
  <database></database>
  <host>127.0.0.1</host>
  <library>
  <filename>libMySQL.dll</filename>
  <tunnel_url></tunnel_url>
  </library>
  <password encode="none">daqin</password>
  <port>3306</port>
  <user>daqin</user>
 </connection>
 <favorites />
 </account>
</accounts>

python處理XML、HTML的利器PyQuery

我出于要練習(xí)的目的,想要用python的XML標(biāo)準(zhǔn)庫處理XML ,但是發(fā)python 內(nèi)置提供了好幾種方法:xml.sax xml.dom xml.minidom

以及還有xml.parsers.expat ,選擇太多,還是決定用PyQuery,PyQuery是依賴于lxml實(shí)現(xiàn)的jquery風(fēng)格的xml解析和處理庫。

lxml算是python很重要的庫了,已知pandas,BeautifulSoup等等這些庫有部分功能依賴lxml。

輸入命令安裝即可:

pip install pyquery

看完教程后就能把代碼寫出來了↓↓↓

python3 讀取 MySQL-Front 的密碼:

# -*- coding: utf-8 -*-
"""
Created on 2017-04-22 22:53:35

@author: codegay
"""
import os
from pyquery import PyQuery as pyq

xmlpath = os.environ['appdata']+r'\MySQL-Front\Accounts.xml'

root = pyq(filename=xmlpath)
for r in root('connection').items():
 print("----------------------------------------------")
 print('host:',r('host').text())
 print('username:',r('user').text())
 print('password:',r('password').text())

運(yùn)行代碼后輸出:

----------------------------------------------
host: 127.0.0.1
username: root
password: root
----------------------------------------------
host: 127.0.0.1
username: daqin
password: daqin

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評論