python生成随机mac地址的方法

yipeiwu_com6年前Python基础

本文实例讲述了python生成随机mac地址的方法。分享给大家供大家参考。具体实现方法如下:

#!/usr/bin/python
import random
def randomMAC():
    mac = [ 0x52, 0x54, 0x00,
        random.randint(0x00, 0x7f),
        random.randint(0x00, 0xff),
        random.randint(0x00, 0xff) ]
    return ':'.join(map(lambda x: "%02x" % x, mac))
print randomMAC()

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Django web框架使用url path name详解

Django web框架使用url path name详解

quicktool/view.py文件修改视图函数index(),渲染一个home.html模板 from django.shortcuts import render def in...

Python Tkinter实现简易计算器功能

Python Tkinter实现简易计算器功能

闲暇时间用tkinter写了个简易计算器,可实现简单的加减乘除运算,用了Button和Entry2个控件,下面是代码,只是简单的用了偏函数partial,因为那么多button的大部分参...

Pandas:Series和DataFrame删除指定轴上数据的方法

如下所示: import numpy as np import pandas as pd from pandas import Series,DataFrame 一、drop方法:...

Python求两点之间的直线距离(2种实现方法)

方法一: #导入math包 import math #定义点的函数 class Point: def __init__(self,x=0,y=0): self.x=x...

python下setuptools的安装详解及No module named setuptools的解决方法

前言 python下的setuptools带有一个easy_install的工具,在安装python的每三方模块、工具时很有用,也很方便。 安装setuptools前先安装pip,请参...