-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacgenerate.py
More file actions
60 lines (47 loc) · 2.06 KB
/
macgenerate.py
File metadata and controls
60 lines (47 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'''
Mac Address Generator
Will output a list of randomized mac addresses per RFC 7042.
This is used to simulate endpoints, endpoint purge policy testing in ISE, or whatever
'''
import random
import argparse
from colorama import Fore,Style
import random
import argparse
from colorama import Fore, Style
def mac_add_generate(is_random=False, delimiter=""):
mac = ""
for i in range(12):
n = random.randrange(16)
mac += f"{n:01x}" # Convert to hexadecimal and append to MAC
if i % 2 == 1 and i < 11: # Add delimiter after every two hex digits, except the last
mac += delimiter
if is_random:
mac = make_randomized(mac)
return mac
def make_randomized(mac):
rando_char = ["2", "6", "a", "e"]
rando_index = random.randrange(4)
mac_list = list(mac)
mac_list[1] = rando_char[rando_index]
return ''.join(mac_list)
def validate_delimiter(delimiter):
return delimiter in [":", "-"]
if __name__ == "__main__":
parser = argparse.ArgumentParser(
prog="Mac Address Generator",
description="Generates MAC addresses with specified parameters, including randomized MACs."
)
parser.add_argument("-c", "--count", type=int, default=10, help="How many MAC addresses to generate.")
parser.add_argument("-d", "--delimiter", type=str, help="MAC Address delimiter. Supported delimiters: ':', '-'", required=False)
parser.add_argument("-r", "--randomized", action="store_true", help="Add if you want randomized MAC addresses")
args = parser.parse_args()
if args.delimiter and not validate_delimiter(args.delimiter):
print(f"{Fore.LIGHTRED_EX}{args.delimiter} is an invalid delimiter. Supported delimiters are ':' or '-'{Style.RESET_ALL}")
quit()
delimiter = args.delimiter or ""
mac_list = [mac_add_generate(args.randomized, delimiter) for _ in range(args.count)]
for mac in mac_list:
print(mac)
mac_type = "randomized" if args.randomized else ""
print(f"{Fore.LIGHTGREEN_EX}Generated {args.count} {mac_type} mac addresses{Style.RESET_ALL}")