Chinaunix首页 | 论坛 | 博客
  • 博客访问: 392503
  • 博文数量: 77
  • 博客积分: 2031
  • 博客等级: 大尉
  • 技术积分: 855
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-15 19:54
文章分类

全部博文(77)

文章存档

2011年(1)

2009年(52)

2008年(24)

我的朋友

分类: Python/Ruby

2009-03-14 12:54:23

#!/usr/bin/python
import os
import re
CmdLine = 'arp -n'
r = os.popen(CmdLine).read()
L = re.findall('10.26.12.1.*?([0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2})', r)
ret = L[0]
print ret

*****************************


import os
import re

def GetMac():
#Windows下的
    if os.name == 'nt':
        try:
            ret = ''
            CmdLine = 'ipconfig /all'
            r = os.popen(CmdLine).read()
            if r:
                L = re.findall('Physical Address.*?([0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2}-[0-9,A-F]{2})', r)
                if len(L) > 0:
                    ret = L[0]
        except:
            pass
       
#Linux/Unix下
    elif os.name == "posix":
        try:
            ret = ''
            CmdLine = 'ifconfig'
            r = os.popen(CmdLine).read()
            if r:
                L = re.findall('HWaddr.*?([0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2}:[0-9,A-F]{2})', r)
                if len(L) > 0:
                    ret = L[0]
        except:
            pass
    else:
        pass
    return ret

if __name__ == '__main__':
    mac =  GetMac()
    print mac

阅读(2632) | 评论(0) | 转发(0) |
0

上一篇:Python编写网络抓包脚本

下一篇:Sniffer原理

给主人留下些什么吧!~~