OP 09 May, 2020 - 01:02 PM
So I am new in Python and I am trying to make a MAC address changer.
This is my code:#!/usr/bin/env python
import subprocess
import optparse
def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address")
parser.add_option("-m", "--mac", dest="new_mac", help="New MAC address")
(options, arguments) = parser.parse_args()
if not options.interface:
parser.error("[-] Please specify an interface. Use --help for more info.")
elif not options.new_mac:
parser.error("Please specify a MAC address. Use --help for more info.")
return options
def change_mac(interface, new_mac):
print("[+] MAC address of " + interface + " successfully changed to " + new_mac)
subprocess.call(["ifconfig", interface, "down"])
subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
subprocess.call(["ifconfig", interface, "up"])
options = get_arguments()
change_mac(options.interface, options.new_mac)
When i try to run this program with the following command: python mac_changer.py -i eth0 -m 00:11:22:33:44:55
I get the following error:
Traceback (most recent call last):
File "mac_changer.py", line 28, in <module>
change_mac(options.interface, options.new_mac)
AttributeError: 'NoneType' object has no attribute 'interface'
Someone please help me
This is my code:#!/usr/bin/env python
import subprocess
import optparse
def get_arguments():
parser = optparse.OptionParser()
parser.add_option("-i", "--interface", dest="interface", help="Interface to change its MAC address")
parser.add_option("-m", "--mac", dest="new_mac", help="New MAC address")
(options, arguments) = parser.parse_args()
if not options.interface:
parser.error("[-] Please specify an interface. Use --help for more info.")
elif not options.new_mac:
parser.error("Please specify a MAC address. Use --help for more info.")
return options
def change_mac(interface, new_mac):
print("[+] MAC address of " + interface + " successfully changed to " + new_mac)
subprocess.call(["ifconfig", interface, "down"])
subprocess.call(["ifconfig", interface, "hw", "ether", new_mac])
subprocess.call(["ifconfig", interface, "up"])
options = get_arguments()
change_mac(options.interface, options.new_mac)
When i try to run this program with the following command: python mac_changer.py -i eth0 -m 00:11:22:33:44:55
I get the following error:
Traceback (most recent call last):
File "mac_changer.py", line 28, in <module>
change_mac(options.interface, options.new_mac)
AttributeError: 'NoneType' object has no attribute 'interface'
Someone please help me