gpt4 book ai didi

python - 为什么输出显示内存代码?

转载 作者:行者123 更新时间:2023-12-01 06:29:04 32 4
gpt4 key购买 nike

我试图将 MAC 地址与 ifconfig 命令隔离,但输出显示的是我认为是内存代码的内容。我在 VB Kali 上运行 python 2.7。

root@osboxes:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.22 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::1171:bf6a:17f8:972 prefixlen 64 scopeid 0x20<link>
ether 08:00:27:f8:15:03 txqueuelen 1000 (Ethernet)
RX packets 2593 bytes 3769210 (3.5 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 794 bytes 57174 (55.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

输入:

#!/usr/bin/env python

import subprocess
import re


def mac_1(network):
output_check = subprocess.check_output(['ifconfig', network])
re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", output_check)
# print(output_check)


print('[+] MAC Address is ' + str(mac_1))

输出代码:

/root/PycharmProjects/test001/venv/bin/python /root/PycharmProjects/test001/test001.py
[+] MAC Address is <function mac_1 at 0x7ff4ed70e3b0>

Process finished with exit code 0

最佳答案

str(mac_1),mac_1 是一个函数,因此它会打印该函数在内存中的位置。您需要使用定义中指定的参数来调用它:

def mac_1(network):  # network is the argument

mac_1 函数也没有返回类型,因此即使您使用参数调用它,它也只会打印 None。因此您需要返回搜索的输出。

尽管我可能建议使用不同的 netifaces 。那么就很简单了

>>> addrs = netifaces.ifaddresses('eth0')
>>> addrs[netifaces.AF_LINK]
[{'addr': '00:12:34:56:78:9a'}]

关于python - 为什么输出显示内存代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59991421/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com