python-获取本机mac地址
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python-获取本机mac地址相关的知识,希望对你有一定的参考价值。
1 #!/usr/bin/env python 2 #-*- coding:utf-8 -*- 3 ############################ 4 #File Name: getmac.py 5 #Author: frank 6 #Mail: [email protected] 7 #Created Time:2017-06-05 17:10:51 8 ############################ 9 10 import uuid 11 12 def get_mac_address(): 13 mac=uuid.UUID(int = uuid.getnode()).hex[-12:].upper() 14 #return ‘%s:%s:%s:%s:%s:%s‘ % (mac[0:2],mac[2:4],mac[4:6],mac[6:8],mac[8:10],mac[10:]) 15 return ":".join([mac[e:e+2] for e in range(0,11,2)]) 16 17 if __name__ == ‘__main__‘: 18 ##name = "test_name" 19 #namespace = "test_namespace" 20 21 print get_mac_address() 22 ‘‘‘ 23 u=uuid.uuid1() # 带参的方法参见Python Doc 24 print u 25 #print uuid.uuid3(namespace, name) 26 #print uuid.uuid4() 27 #print uuid.uuid5(namespace, name) 28 node1=uuid.getnode() #获取mac地址 29 print ("node1:%s"%node1) 30 print ("hex(node1):%s"%hex(node1)) 31 print ("uuid.bytes:%s"%repr(u.bytes)) 32 print ("uuid.bytes_le:%s"%repr(u.bytes_le)) 33 print ("hex:", u.hex) 34 print ‘int :‘, u.int 35 print ‘urn :‘, u.urn 36 print ‘variant :‘, u.variant 37 print ‘version :‘, u.version 38 #print get_mac_address() 39 ‘‘‘
以上是关于python-获取本机mac地址的主要内容,如果未能解决你的问题,请参考以下文章