Generate MAC-addresses

Fra SemarkIT
Skift til: Navigation, Søgning

There can be many reasons for that you want to generate a MAC, eg. for your XEN system or a virtual interface.

NB. For good measures I have to tell that I have not created this python-script and is in no way responsible for your systems behavior

nano ~/GenerateMacAdresses
#!/usr/bin/env python 

# Quick Python script to generate random valid MAC address for XEN Domains
# Copyright (C) 2008 Allen Sanabria
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. 

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

# This address range is reserved for use by Xen 00:16:3E
# I'm importing the function choice of the random module
# The reason for this is so that it will pick a random
# character from the string I gave it to generate a valid MAC for XEN 

from random import choice
from sys import stdin 

def x():
    X = choice("0123456789ABCDEF")
    return str(X) 

print "Enter how many MAC Addresses do you want me to generate: "
mac = stdin.readline()
mac_list = []
for i in range(int(mac)):
    mac_list.append("00:16:3E"+":"+x()+x()+":"+x()+x()+":"+x()+x())
for con in range(len(mac_list)):
    while mac_list.count(mac_list[con]) > 1:
        print "OH NOOO DUPPPE "+mac_list[con]
    mac_list.pop(con)
    mac_list.insert(con, "00:16:3E"+":"+x()+x()+":"+x()+x()+":"+x()+x())
    print mac_list[con]
chmod +x ~/GenerateMacAdresses
./GenerateMacAdresses

Output:

Enter how many MAC Addresses do you want me to generate:
9
00:16:3E:35:E9:C2
00:16:3E:7C:F8:D7
00:16:3E:80:C2:FB
00:16:3E:6D:AB:27
00:16:3E:81:AF:30
00:16:3E:DB:FD:86
00:16:3E:55:69:F8
00:16:3E:9B:8E:C9
00:16:3E:B2:85:FC
Personlige værktøjer
Navnerum

Varianter
Handlinger
Navigation
Værktøjer