Python绝技笔记--------python操作注册表来获取之前连接的网络信息

出现了错误。异常 259.。。。。。。
先记录下代码,有空在研究研究是哪里出错了。若有大神看到也请指点下萌新

# -*- coding: UTF-8 -*-
from _winreg import *
#REG_BINARY the MAC change 16

def va12addr(val):
    addr=""
    for ch in val:
        addr += ("%02x" %ord(ch))
    addr = addr.strip(' ').replace(" ",":")[0:17]
    print addr
    return addr

#获取 注册表中的网络信息

def printNets():
    net =r"SOFTWARE\Microsoft\Windows NT\CurrentVersion"+"\NetworkList\Signatures\Unmanaged"
    key = OpenKey(HKEY_LOCAL_MACHINE,net)
    print '\n[+] Networks You have Joined.'
    print key
    for i in range(100):
        try:
            guid = EnumKey(key,i)
            print guid
            netKey = OpenKey(key,str(guid))
            (n,addr,t) = EnumValue(netKey,5)
            (n,name,t) = EnumValue(netKey,4)
            macaddr = va12addr(addr)
            netName = str(name)
            print '[+] '+netName +' '+macaddr
            CloseKey(netKey)
        except Exception,e:
            print e
            break

def main():
    printNets()
if __name__=='__main__':
    main()

Python绝技笔记--------python操作注册表来获取之前连接的网络信息_第1张图片

详细的_winreg 可以看
http://blog.sina.com.cn/s/blog_1574497330102wjfg.html

http://blog.csdn.net/joeblackzqq/article/details/38960659

你可能感兴趣的:(Python,python绝技笔记,安全)