feross / SpoofMAC

:briefcase: Change your MAC address for debugging
https://feross.org/spoofmac/
3.03k stars 269 forks source link

List command should show current MAC address #10

Closed feross closed 11 years ago

feross commented 11 years ago

@TkTech – code review for this?

TkTech commented 11 years ago

Might be worthwhile for find_interfaces to return a namedtuple,

Interface = namedtuple('Interface', [
    'port',
    'device',
    'hard_address',
    'soft_address'
])

...instead of unpacking the results each time.

I also wouldn't use PIPE, instead of using grep just use re.match from python and use check_call instead of Popen.

Just my opinion, otherwise it looks fine.

feross commented 11 years ago

I'm using PIPE to suppress messages to stderr because sometimes ifconfig complains about the device not existing. And I'm using Popen instead of check_call because I'm interested in the output of ifconfig. I don't think check_call gives you output. Is there a better way to do this?

TkTech commented 11 years ago

Something simple along the lines of (untested):

result = subprocess.check_output(
    'ifconfig {device}'.format(device=device),
    stderr=subprocess.STDOUT
)
# Optionally handle that case, no idea what the actual string is:
if 'device does not exist' in result:
    # Error out?
    pass

<do the regex here>
feross commented 11 years ago

K, done.