import subprocess
import optparse
import re
def add_value ():
pharse=optparse.OptionParser()
pharse.add_option("-i","--interface", dest="interface",help="Indicate a Interface")
pharse.add_option("-m","--mac",dest="mac", help="new MAC address ")
(options,arguments)= pharse.parse_args()
if not options.interface:
pharse.error("[-] Cannot find any interface to work on" )
elif not options.mac:
pharse.error("[-] Suggest a mac adress to be changed")
def change_mac (interface,mac):
print("[-] Changing MAC adress of"+interface+"to"+mac)
subprocess.call(["ifconfig",interface,"down"])
subprocess.call(["ifconfig",interface,"hw", "ether",mac])
subprocess.call(["ifconfig",interface,"up"])
def check_stats(interface):
changed_mac= subprocess.check_output("ifconfig",interface)
ifconfig_check= re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w",changed_mac)
if ifconfig_check:
return ifconfig_check.group(0)
else:
print("[-] Could not print mac adress of"+ interface)
options= add_value()
old_mac=check_stats(options.interface)
print(str(old_mac))
change_mac(options.interface,options.mac)
new_mac =check_stats(options.interface)
if new_mac==options.mac:
print("[+]The MAC address was changed to "+str(new_mac))
else :
print("[-]Mac address was not changed")