美文网首页
改变MAC Address Linux

改变MAC Address Linux

作者: Hack_J | 来源:发表于2019-08-24 22:49 被阅读0次
    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

          本文链接:https://www.haomeiwen.com/subject/hrafectx.html