Random MAC generator error

Denis McMahon denismfmcmahon at gmail.com
Sat Sep 12 22:31:12 CEST 2015


On Sun, 13 Sep 2015 00:50:24 +0530, Robert Clove wrote:

> import random #
> 
> global mac1 
> def randomMAC():
> 	mac = [ 0x00, 0x16, 0x3e,
> 		random.randint(0x00, 0x7f), random.randint(0x00, 0xff),
> 		random.randint(0x00, 0xff) ]
> 	return ':'.join(map(lambda x: "%02x" % x, mac))
> #
> print randomMAC()
> 
> for x in range(1,11):
> 
>      mac1 = randomMAC()
> 
>      print mac1
> 
> I got the following random mac generator script from the net (simple
> google search)
> 
> i want to use random mac in one of mine script.What i need is
> mac1=randomMAC() should give mac value to mac1 that i use in a function
> and this runs in a loop.

And you haven't told us what the "error" you're posting about is?

When I ran the code I got the following result:

00:16:3e:21:da:a4
00:16:3e:57:be:d2
00:16:3e:6b:e5:ae
00:16:3e:54:0e:f0
00:16:3e:57:5e:50
00:16:3e:21:99:6b
00:16:3e:12:e6:05
00:16:3e:53:02:6d
00:16:3e:79:17:1b
00:16:3e:02:ff:b8
00:16:3e:4e:ff:0d

Observation: No point in declaring mac1 as global in the global scope.

Is it possible that you've tried to run python 2.x code on python 3.x and 
hit an error due to 'print x' -> 'print(x)'?

-- 
Denis McMahon, denismfmcmahon at gmail.com


More information about the Python-list mailing list