改变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)

点击获取代码

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • # Awesome Python [![Awesome](https://cdn.rawgit.com/sindr...
    emily_007阅读 2,227评论 0 3
  • 一、Python简介和环境搭建以及pip的安装 4课时实验课主要内容 【Python简介】: Python 是一个...
    _小老虎_阅读 5,820评论 0 10
  • # Python 资源大全中文版 我想很多程序员应该记得 GitHub 上有一个 Awesome - XXX 系列...
    小迈克阅读 3,055评论 1 3
  • 前些天睡眠紊乱的副作用终于来了,现在感到特别的困,不过还是决定咬咬牙写点什么……希望写完之后,今天能睡个好觉 今天...
    好鱼阅读 198评论 0 0
  • 生活工作中,我们往往会在很多不经意间,错过许多机会和财富。为什么别人会取得成功?能赚大钱?为什么别人就能抓住机会,...
    佰斯拓阅读 247评论 0 1