我不知道它为什么不读我的Mac地址

2024-05-16 00:03:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我开始学习用python编写代码。我正在做一个udemy课程,我必须用python2和pytho3编写一个程序,在kali-linux中读取Mac地址。 我唯一的问题是,我的re.search命令没有将我的旧Mac地址读到底,而是更改了它。我真的认为代码很好。就在这里,希望有人能帮助我


def get_current_mac(interface):
    ifconfig_result = subprocess.check_output(["ifconfig", interface])
    mac_address_search_result = re.search(r" \w\w:\w\w:\w\w:\w\w:\w\w:\w\w ", ifconfig_result)

    if mac_address_search_result:
        return mac_address_search_result
    else:
        print(" Could not read Mac Address ")

下面是出现的错误:

Current mac =<_sre.SRE_Match object at 0x7f7ebbf22ab0>

Changing MAC address for eth0 to 11:22:33:44:44:11

SIOCSIFHWADDR: Cannot assign requested address

Error, try again

谢谢,我真的希望能得到一些帮助


Tags: 代码程序researchaddressmac地址result