feross / SpoofMAC

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

Add command ip support for linux platform #58

Closed lublud closed 8 years ago

lublud commented 8 years ago

Being a arch linux user, ip has been chosen over ifconfig deprecated.

I thus changed a bit the code so I can use it with ip.

Tested only on arch linux.

feross commented 8 years ago

Please address my inline comment, then I'm happy to merge this.

lublud commented 8 years ago

Yes indeed, my bad, shouldn't change.. I fix that.

feross commented 8 years ago

Released as 2.1.0.

@lublud Please install and make sure it works for you.

lublud commented 8 years ago

Working fine for me, thanks!

tkelman commented 8 years ago

It looks like there are more uses of ifconfig on lines 147 and 129 of this file that it would be good to find workarounds for, if possible. On OpenSUSE 42.1, ifconfig is at /sbin/ifconfig which is not on the default path of a non-root user:

tkelman@linux:~> spoof-mac --version
2.1.0
tkelman@linux:~> spoof-mac list
Traceback (most recent call last):
  File "/usr/bin/spoof-mac", line 138, in <module>
    sys.exit(main(arguments, root_or_admin))
  File "/usr/bin/spoof-mac", line 76, in main
    list_interfaces(args, spoofer)
  File "/usr/bin/spoof-mac", line 56, in list_interfaces
    for port, device, address, current_address in spoofer.find_interfaces(targets=targets):
  File "/usr/lib/python2.7/site-packages/spoofmac/interface.py", line 147, in find_interfaces
    output = subprocess.check_output(["ifconfig"], stderr=subprocess.STDOUT, universal_newlines=True)
  File "/usr/lib64/python2.7/subprocess.py", line 566, in check_output
    process = Popen(stdout=PIPE, *popenargs, **kwargs)
  File "/usr/lib64/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib64/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory
feross commented 8 years ago

@tkelman PRs welcome!

tkelman commented 8 years ago

Not sure what the best solution would be - locally changing ifconfig to /sbin/ifconfig works on my system, but would that be appropriate on other distros?

feross commented 8 years ago

What about using /sbin/ifconfig when it exists, otherwise use the current command name?

tkelman commented 8 years ago

I like that idea. I guess it would also likely be needed on lines 193, 196, 451, and 472 if I had hit those.

edit: 451 and 472 are for osx, and there's an easier fix using /bin/ip

feross commented 8 years ago

Probably best to check once and set a variable with the command to use, then use that throughout.

On Sun, Jan 3, 2016 at 4:16 AM Tony Kelman notifications@github.com wrote:

I like that idea. I guess it would also likely be needed on lines 193, 196, 451, and 472 if I had hit those.

— Reply to this email directly or view it on GitHub https://github.com/feross/SpoofMAC/pull/58#issuecomment-168455861.