小绿和小蓝 堆糖:如果得到网卡mac地址
来源:百度文库 编辑:中财网 时间:2024/04/28 15:42:37
>>> import uuid
>>> node = uuid.getnode()
>>> mac = uuid.UUID(int=node)
>>> addr = mac.hex[-12:]
>>> addr
'001a4d71d4ca' 自动化运维案例分享讨论之二(大奖)|ChinaUnix活动列表 积分好礼等你拿! | Linux平台存储大家谈! | ChinaUnix十年十城沙龙ppt下载
ibetibet当前离线
在其_ipconfig_getnode()函数的基础上,我添加了一个函数,考虑多个网卡的情况:
def ipconfig_getnode(id):
"""----add by liangzi----get mac if have more than one newwork hardware"""
import os, re
dirs = ['', r'c:\windows\system32', r'c:\winnt\system32']
try:
import ctypes
buffer = ctypes.create_string_buffer(300)
ctypes.windll.kernel32.GetSystemDirectoryA(buffer, 300)
dirs.insert(0, buffer.value.decode('mbcs'))
except:
pass
macad=[]
for dir in dirs:
try:
pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
except IOError:
continue
for line in pipe:
value = line.split(':')[-1].strip().lower()
if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
macad.append(value) #我需要的字符串
#macad.append(int(value.replace('-', ''), 16)) 这里是返回数字
return macad[id]
>>> node = uuid.getnode()
>>> mac = uuid.UUID(int=node)
>>> addr = mac.hex[-12:]
>>> addr
'001a4d71d4ca' 自动化运维案例分享讨论之二(大奖)|ChinaUnix活动列表 积分好礼等你拿! | Linux平台存储大家谈! | ChinaUnix十年十城沙龙ppt下载
ibetibet当前离线
- 空间积分
- 0
- 信誉积分
- 100
- UID
- 51397
- 阅读权限
- 10
- 积分
- 3
- 帖子
- 4
- 精华
- 0
- 可用积分
- 3
- 专家积分
- 0
- 在线时间
- 2 小时
- 注册时间
- 2006-11-20
- 最后登录
- 2010-05-06
白手起家
白手起家, 积分 3, 距离下一级还需 197 积分- 帖子
- 4
- 主题
- 1
- 精华
- 0
- 可用积分
- 3
- 专家积分
- 0
- 在线时间
- 2 小时
- 注册时间
- 2006-11-20
- 最后登录
- 2010-05-06
- 串门
- 好友
- 博客
- 消息
- 论坛徽章:
- 0
在其_ipconfig_getnode()函数的基础上,我添加了一个函数,考虑多个网卡的情况:
def ipconfig_getnode(id):
"""----add by liangzi----get mac if have more than one newwork hardware"""
import os, re
dirs = ['', r'c:\windows\system32', r'c:\winnt\system32']
try:
import ctypes
buffer = ctypes.create_string_buffer(300)
ctypes.windll.kernel32.GetSystemDirectoryA(buffer, 300)
dirs.insert(0, buffer.value.decode('mbcs'))
except:
pass
macad=[]
for dir in dirs:
try:
pipe = os.popen(os.path.join(dir, 'ipconfig') + ' /all')
except IOError:
continue
for line in pipe:
value = line.split(':')[-1].strip().lower()
if re.match('([0-9a-f][0-9a-f]-){5}[0-9a-f][0-9a-f]', value):
macad.append(value) #我需要的字符串
#macad.append(int(value.replace('-', ''), 16)) 这里是返回数字
return macad[id]
怎么能得到一个IP的网卡MAC地址?
黑客得到网卡MAC地址有什么用?
网卡mac地址相关
网卡的MAC地址
网卡的MAC地址
如果我换网卡了 还用改MAC地址吗?
如果在LINUX下修改网卡的MAC地址?
网卡MAC地址可否更改?
网卡的MAC地址能改吗
怎么修改网卡MAC地址
网卡的MAC地址可改吗...
怎样获得网卡MAC地址
MAC就是网卡地址吗?
如何绑定网卡MAC地址
如果网上有人和我的网卡MAC地址一样会出现什么情况?
请教更改网卡的MAC地址.
网卡上的MAC地址如何更改??
网卡上的MAC地址如何更改?
为什么两块网卡MAC地址相同?
请问如何修改网卡mac地址
请问如何修改网卡mac地址
网卡的MAC地址有无办法修改?
网卡的MAC地址可以改吗?
主板集成网卡刷新MAC地址