改变MAC Address Linux

ifconfig "interface_name" down
ifconfig "interface_name" hw ether "mac_addr"
ifconfig "interface_name" up

Python Program

import subprocess
subprocess.call('command',shell=True) #根据不同平台调用不同系统命令

Subprocess Documents

import subprocess
def changeMacTo(mac_add, interface):
  subprocess.call("ifconfig " + interface +" down",shell=True)
  subprocess.call("ifconfi " + interface +" hw ether " + mac_addr, shell=True)
  subprocess.call("ifconfig " + interface +" up",shell=True)
if __name__ == "__main__":
  changeMacTo("00:11:22:33:44:55","wlan0")
#With command line args 
import optparse
import subprocess
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()
interface = options.interface
mac_addr = options.new_mac
subprocess.call("ifconfig " + interface +" down",shell=True)
subprocess.call("ifconfig " + interface +" hw ether " + mac_addr, shell=True)
subprocess.call("ifconfig " + interface +" up",shell=True)

点击获取代码

你可能感兴趣的:(改变MAC Address Linux)