python 學習之 WINDOWS 註冊表學習(一)

文章出自《Python絕技 運用Python成爲頂級***》中部分代碼,稍做修改網絡


遍歷Windows註冊表鍵值,代碼以下:ide

import _winreg
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer")
try:
        i=0
        while 1:ui

#EnumValue枚舉鍵值,EnumKey枚舉子鍵(guid=_winrge.EnumKey(key,i))
        name,value,type=_winreg.EnumValue(key,i)
        print "name: "+repr(name)
        print "type: "+repr(type)
        print "value: "+repr(value)
        print "__________________________"
        i+=1
except WindowsError:
        print
操作系統


效果blog

wKioL1hrUcmhbb16AAA0ISmItxM872.png-wh_50


下面咱們編寫個在WINDOWS操做系統中,查找曾經訪問過的有線網絡和無線網絡,對應的網關的Mac地址的腳本圖片

import _winreg
def val2addr(val):
        addr=''
        for ch in val:ip

#ord 做用:字符轉換爲10進制整數 ;"%02x"以16進制輸出變量,若是輸出的變量不足2位用0補足
            addr+='%02x '% ord(ch)
            addr=addr.strip(' ').replace(' ',':')[0:17]
        return addr
def printNets():
        net=r"SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkList\Signatures\Unmanaged"
        key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,net)
        print '\n[*] Networks You have Joined.'
        for i in range(100):
                try:
                        guid=_winreg.EnumKey(key,i)
                        netKey=_winreg.OpenKey(key,str(guid))
                        n,addr,t=_winreg.EnumValue(netKey,5)
                        macAddr=repr(addr)
                        n,name,t=_winreg.EnumValue(netKey,4)
                        netName=repr(name)
                        macAddr=val2addr(addr)
                        print '[+] '+netName+' '+macAddr
                        _winreg.CloseKey(netKey)
                except WindowsError:
                        print
def main():
        printNets()
if __name__=="__main__":
        main()get

相關文章
相關標籤/搜索