Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import subprocess
  2. import re
  3. import optparse
  4.  
  5. def get_arguments():
  6.     parser = optparse.OptionParser()
  7.     parser.add_option('-i', '--interface', dest='interface', help="--help for more info")
  8.     parser.add_option('-m', '--mac', dest='new_mac', help="--help for more info")
  9.     (options, arguments) = parser.parse_args()
  10.     return options
  11.  
  12. def change_mac(interface, new_mac):
  13.     subprocess.call(['ifconfig', options.interface, 'down'])
  14.     subprocess.call(['ifconfig', options.interface, 'hw', 'ether', options.new_mac])
  15.     subprocess.call(['ifconfig', options.interface, 'up'])
  16.  
  17. def get_current_mac(interface):
  18.     ifconfig_result = subprocess.check_output(['ifconfig', interface])
  19.     mac_address_result = re.search(r'\w\w:\w\w:\w\w:\w\w:\w\w:\w\w', ifconfig_result)
  20.  
  21.     if mac_address_result:
  22.         return mac_address_result.group(0)
  23.     else:
  24.         print('[-] Could not find MAC address')
  25.        
  26. options = get_arguments()
  27. current_mac = get_current_mac(options.interface)
  28.  
  29. change_mac(options.interface, options.new_mac)
  30.  
  31. print(get_current_mac(options.interface))
  32. print('Your new mac address is {}'.format(current_mac))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement