import random
import os
import subprocess

# Pick random value from the string given
def get_rand():
    return random.choice("abcdef0123456789")

# Create a new MAC address using the random function
def create_mac():
    new = ""
    for i in range(0,5):
        new += get_rand() + get_rand() + ":"
    
    new += get_rand() + get_rand()

    return new

# Call the following command in the console to get the current MAC address 
print(os.system("ifconfig ens33 | grep ether | grep -oE [0-9abcdef:]{17}"))

# Use subprocess to call the following command, each command/argument is seperated
subprocess.call(["sudo", "ifconfig", "ens33", "down"])

# Create the new MAC adddress using the methods we made above
new_m = create_mac()
# print(new_m)

# Assign the new MAC address that we created to the current machnine
subprocess.call(["sudo", "ifconfig", "ens33", "hw", "ether","%s"%new_m])
# Reversing the down call that we made earlier
subprocess.call(["sudo", "ifconfig", "ens33", "up"])    

# Checking the MAC address that we have changed
print(os.system("ifconfig ens33 | grep ether | grep -oE [0-9abcdef:]{17}"))