[dundee] Virtual Xen Network Interfaces

gordon dunlop astrozubenel at googlemail.com
Wed Oct 29 16:23:00 UTC 2008


2008/10/29 Andrew Clayton <andrew at digital-domain.net>:
> On Wed, 29 Oct 2008 15:50:38 +0000, gordon dunlop wrote:
>
>> When a Xen virtual machine is created a virtual MAC address is
>> generated into the Xen virtual machine configuration file. Some people
>> like to do configure this virtual MAC address for different reasons.
>> All Xen virtual MAC addresses are 00:16:3e:xxx:xx:xx, potentially
>> approx 12 million MAC addresses. I was looking in how to produce a
>> python script that could randomly generate these virtual addresses
>> with a user input defining the number of addresses to generate. I am
>> stuck as I can only produce copies of the one MAC address due to the
>> random generator only executing once. I have tried to use loops and
>> iterations to produce the different MAC addresses but to no avail.
>> Here is what I have got to so far in my Python script.
>>
>> #!/usr/bin/python
>> # xenvirtualmac.py - Generating virtual MAC Addresses with user input
>> #
>> import random
>> mac = [ 0x00, 0x16, 0x3e,
>> random.randint(0x00, 0x7f),
>> random.randint(0x00, 0xff),
>> random.randint(0x00, 0xff) ]
>> n = int(raw_input('Enter number of MAC Addresses: '))
>> i = iter(mac)
>> for j in range(1,n + 1):
>>      print 'MAC Addresses', j, ':'.join(map(lambda x: "%02x" % x,
>> mac))
>>
>> If anyone has ideas please let me know.
>
> This seems to work
>
> #!/usr/bin/python
> # xenvirtualmac.py - Generating virtual MAC Addresses with user input
> #
> import random
> n = int(raw_input('Enter number of MAC Addresses: '))
> for j in range(1,n + 1):
>        mac = [ 0x00, 0x16, 0x3e,
>                random.randint(0x00, 0xff),
>                random.randint(0x00, 0xff),
>                random.randint(0x00, 0xff) ]
>
>        print 'MAC Addresses', j, ':'.join(map(lambda x: "%02x" % x, mac))
>
Thanks Andrew I owe you a pint, now I see it, get rid of the iteration
and have the Random generation at the end.

Gordon
>
>
>
> _______________________________________________
> dundee GNU/Linux Users Group mailing list
> dundee at lists.lug.org.uk  http://dundee.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/dundee
> Chat on IRC, #tlug on dundee.lug.org.uk
>



More information about the dundee mailing list