I built a class to change my mac address (not sure if this is the cleanest way to do so)
#!/usr/bin/env python3
import subprocess
class MacAdress:
global interface
interface = input("enter interface:\t")
def change_Mac(self=interface):
mac = '00:11:22:ff:ff:ff'
subprocess.call(f"sudo -S ifconfig {interface} down", shell=True)
subprocess.call(f'sudo -S ifconfig {interface} hw ether {mac}', shell=True)
subprocess.call(f"sudo -S ifconfig {interface} up", shell=True)
def Restore_Mac(self=interface):
old_mac = ''
subprocess.call(f"sudo -S ifconfig {interface} down", shell=True)
subprocess.call(f'sudo -S ifconfig {interface} hw ether {old_mac}', shell=True)
subprocess.call(f"sudo -S ifconfig {interface} up", shell=True)
I was wondering if there is a way to store the root password so it only prompts one time similar to how interface is used, instead of using sudo -S for each command.old mac is left blank intentionally. Any tips for cleaning this up to be more professional would be greatly appreciated as well.