I am trying to isolate the MAC Address from the ifconfig
command but the output is displaying what I believe is memory code. I am running python 2.7 on a VB Kali.
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
Input:
#!/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))
Output Code:
/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 is a function so it's printing the location of that function in memory. You need to call it with an argument as you specified in the definition:
def mac_1(network): # network is the argument
The mac_1
function also doesn't have a return type, so even if you called it with an argument it will just print None
. So you need to return the output of your search.
Though I might suggest just using a different netifaces . Then it's as simple as
>>> addrs = netifaces.ifaddresses('eth0')
>>> addrs[netifaces.AF_LINK]
[{'addr': '00:12:34:56:78:9a'}]
I figure this out a few days ago and haven't had time to respond. Here is the result that I was looking for:
Input
#!/usr/bin/env python
import subprocess
import re
output_check = subprocess.check_output(['ifconfig'])
check = re.search(r"\w\w:\w\w:\w\w:\w\w:\w\w:\w\w", output_check)
print("Mac Address is: " + check.group(0))
Output
Mac Address is: 08:69:18:f9:85:06
Thank you all for your help
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.