【发布时间】:2020-01-30 17:29:42
【问题描述】:
我正在尝试将 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 是一个函数,因此它会打印该函数在内存中的位置。 -
改为致电
str(mac_1, 'eth0') -
mac_1()不返回任何内容。你希望它打印什么? -
@samthegolden 你的意思是
str(mac_1('eth0')) -
是的@Barmar 我的坏
标签: python regex memory subprocess output