feross / SpoofMAC

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

Python 3.5 UnicodeDecodeError #56

Closed RomaEcho closed 8 years ago

RomaEcho commented 8 years ago

Hi, trying to launch spoofmac on python3.5, windows 8. command spoof-mac -help works correct, but spoof-mac list :

C:\Python35\Scripts> spoof-mac list Traceback (most recent call last): File "C:\Python35\Scripts\spoof-mac.py", line 138, in sys.exit(main(arguments, root_or_admin)) File "C:\Python35\Scripts\spoof-mac.py", line 76, in main list_interfaces(args, spoofer) File "C:\Python35\Scripts\spoof-mac.py", line 56, in list_interfaces for port, device, address, current_address in spoofer.find_interfaces(targets=targets): File "c:\python35\lib\site-packages\spoofmac\interface.py", line 185, in find_interfaces output = self.get_ipconfig_all() File "c:\python35\lib\site-packages\spoofmac\interface.py", line 149, in get_ipconfig_all return result.decode('ascii') UnicodeDecodeError: 'ascii' codec can't decode byte 0x8d in position 2: ordinal not in range(128)

thewood commented 8 years ago

are you running the script with admin priv?

feross commented 8 years ago

It appears that that's the issue. Run the script as an admin.

RomaEcho commented 8 years ago

I definitely launch command prompt with admin priv, dont know what the problem...

feross commented 8 years ago

Okay, re-opening.

pteek commented 8 years ago

2.0.6 is working on my windows 7 system. Will look into this.

Akarius commented 8 years ago

Same error here. spoofMAC 2.1.1 with python 2.7.10 on Win7 as admin. Traceback (most recent call last): File "spoof-mac.py", line 4, in import('pkg_resources').run_script('spoofmac==2.1.1', 'spoof-mac.py') File "build\bdist.win32\egg\pkg_resourcesinit.py", line 745, in run_script File "build\bdist.win32\egg\pkg_resourcesinit.py", line 1677, in run_script File "C:\Python\Python27\lib\site-packages\spoofmac-2.1.1-py2.7.egg\EGG-INFO\scripts\spoof-mac.py", line 138, in <modu le>

File "C:\Python\Python27\lib\site-packages\spoofmac-2.1.1-py2.7.egg\EGG-INFO\scripts\spoof-mac.py", line 76, in main

File "C:\Python\Python27\lib\site-packages\spoofmac-2.1.1-py2.7.egg\EGG-INFO\scripts\spoof-mac.py", line 56, in list_i nterfaces

File "build\bdist.win32\egg\spoofmac\interface.py", line 266, in find_interfaces File "build\bdist.win32\egg\spoofmac\interface.py", line 230, in get_ipconfig_all UnicodeDecodeError: 'ascii' codec can't decode byte 0x93 in position 46: ordinal not in range(128)

Akarius commented 8 years ago

Just checked in code...and I find why. In the code of interface.py, subprocess.popen is use to get the output of ipconfig /all My system is in french, there are accented characters in the results and the decode('ascii') fails.

feross commented 8 years ago

@Akarius Thanks for digging into this. I don't write Python very often, so I don't know how to fix this. If you send a PR, I will merge it and release a new version.

Akarius commented 8 years ago

@feross I manage to make "spoof-mac.py list" working by altering the encoding of the output to remove the accented characters. I got no result. The problem is that there are many searches for strings like "Physical Address" and "adapter" in the ipconfig /all output (in interface.py) and these are language-dependants and will only work in english and no other languages. You should add a note about it in the README.md to avoid confusion. As this project is about spoofing and not getting your MAC address, a solution would be to use netifaces to get infos about the adapter(s) instead of using subprocess with ipconfig. netifaces does a good job for this but is not included in the standard distribution of python, you have to add it (easy_install and pip can do it easily)

feross commented 8 years ago

@Akarius PR welcome for the doc fix. Also, if you're interested in becoming a maintainer I'll add you.

Marshall13 commented 7 years ago

image

I have exactly the same problem..Has anyone found a solution? My system is also French ^^ I do not know if there is a link

junglist565 commented 6 years ago

I solved the problem by changing the charset from "ascii" to "latin1" on Windows 10 (my system is italian :D ). You also have to change the regex in find_interfaces(self, targets=None) method in your language, by comparing the original English output with yours.

In my case it's something like this:

# search for specific adapter gobble through mac address
details = re.findall("Scheda (.*?):[\\n\\r]+(.*?)\\s*Indirizzo fisico[^\\d]+(\\s\\S+)", output, re.DOTALL)

In any case the script seems to work fine, but in facts it doesn't change the MAC of the specified device (by typing ipconfig /all command nothing has changed).

Anyway it works fine on Linux (I never tried on MacOS), but on Windows has some bugs