unknown mac localename instalar python macos installation importerror scapy

python - mac - La instalación de Scapy falla en osx con error de importación de dnet



raise valueerror(''unknown locale: %s'' % localename) valueerror: unknown locale: utf-8 (5)

Tiene problemas para instalar Scapy y se requieren dependencias. He pasado algún tiempo buscando en Google una solución, pero todas las ''soluciones'' parecen afectar a versiones anteriores de Python, o simplemente no funcionan.

Guión:

#!/usr/bin/python import threading import Queue import time from scapy.all import * class WorkerThread(threading.Thread) : def __init__(self, queue, tid) : threading.Thread.__init__(self) self.queue = queue self.tid = tid print ''Worker: %d'' %self.tid def run(self) : total_ports = 0 while True : port = 0 try : port = self.queue.get(timeout=1) except Queue.Empty : print ''Worker %d exiting. %d ports scanned'' %(self.tid, total_ports) return #Scanning begins ip = sys.argv[1] response = sr1(IP(dst=ip)/TCP(dport=port, flags=''S''), verbose=False, timeout=.2) if response : if response[TCP].flags == 18 : print ''ThreadID: %d: Got port no. %d status: OPEN'' %(self.tid, port) self.queue.task_done() total_ports += 1 queue = Queue.Queue() threads = [] for i in range(1, 10) : print ''Creating WorkerThread : %d'' %i worker = WorkerThread(queue, i) worker.setDaemon(True) worker.start() threads.append(worker) print ''WorkerThread %d created'' %i for j in range(1, 100) : queue.put(j) queue.join() for item in threads : item.join() print ''Scanning complete''

La versión de Python es 2.7.5 y la ruta a Python verificada.

which python /usr/bin/python

Cuando se ejecuta el script, aparece el siguiente error:

./multi-threaded-scanner.py Traceback (most recent call last): File "./multi-threaded-scanner.py", line 6, in <module> from scapy.all import * File "/Library/Python/2.7/site-packages/scapy/all.py", line 16, in <module> from arch import * File "/Library/Python/2.7/site-packages/scapy/arch/__init__.py", line 75, in <module> from bsd import * File "/Library/Python/2.7/site-packages/scapy/arch/bsd.py", line 12, in <module> from unix import * File "/Library/Python/2.7/site-packages/scapy/arch/unix.py", line 20, in <module> from pcapdnet import * File "/Library/Python/2.7/site-packages/scapy/arch/pcapdnet.py", line 160, in <module> import dnet ImportError: No module named dnet

Puedo usar los intérpretes interactivos de Scapy y Python y ejecutar import scapy en el intérprete de Python no produce errores. Cuando el script se ejecutó inicialmente, pcapy módulo pcapy , sin embargo, lo instalé y luego el problema cambió a dnet, para lo cual no puedo encontrar una solución. Una publicación similar , parece describir el mismo problema, pero las soluciones no tienen efecto. ¿Alguien puede arrojar más luz sobre este tema?

Comandos utilizados para instalar pcapy y libdnet:

libdnet-1.11.tar.gz (01-19-2005)

` ~/Downloads/libdnet-1.11  chmod a+x configure ~/Downloads/libdnet-1.11  ./configure && make`

Sale exitosamente

Pcapy: última versión estable (0.10.8), actualizada el 26 de agosto de 2010

~/Downloads/pcapy-0.10.8 
sudo python setup.py install Password: running install running build running build_ext running build_scripts running install_lib running install_scripts changing mode of /usr/local/bin/96pings.pcap to 777 changing mode of /usr/local/bin/pcapytests.py to 777 running install_data running install_egg_info Removing /Library/Python/2.7/site-packages/pcapy-0.10.8-py2.7.egg-info Writing /Library/Python/2.7/site-packages/pcapy-0.10.8-py2.7.egg-info ~/Downloads/pcapy-0.10.8 

Resultados para compilar con nuevas banderas.

~/Downloads/libdnet-1.12  sudo CFLAGS=''-arch i386 -arch x86_64'' ./configure --prefix=/usr and archargs=''-arch i386 -arch x86_64'' make configure: WARNING: you should use --build, --host, --target configure: WARNING: you should use --build, --host, --target checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes /Users/richardcurteis/Downloads/libdnet-1.12/config/missing: Unknown `--is-lightweight'' option Try `/Users/richardcurteis/Downloads/libdnet-1.12/config/missing --help'' for more information configure: WARNING: ''missing'' script is too old or missing checking for a thread-safe mkdir -p... config/install-sh -c -d checking for gawk... no checking for mawk... no checking for nawk... no checking for awk... awk checking whether make sets $(MAKE)... yes checking whether make supports nested variables... yes checking whether to enable maintainer-specific portions of Makefiles... no checking build system type... Invalid configuration `and'': machine `and'' not recognized configure: error: /bin/sh config/config.sub and failed ~/Downloads/libdnet-1.12 


(Esto es un comentario a la respuesta de Tim Wu , pero me falta la reputación para hacerlo)

Ten en cuenta que hacer lo que realmente te dice:

==> Advertencias
Los módulos de Python se han instalado y los paquetes de sitios de Homebrew no están en su sys.path de Python, por lo que no podrá importar los módulos que esta fórmula instaló.
Si planea desarrollar con estos módulos, ejecute: [...]

mkdir -p /Users/YourUsernameHere/Library/Python/2.7/lib/python/site-packages echo ''import site; site.addsitedir("/usr/local/lib/python2.7/site-packages")'' >> /Users/YourUsernameHere/Library/Python/2.7/lib/python/site-packages/homebrew.pth

Así que simplemente vuelva a ejecutar el comando brew y ejecute las dos líneas que le indican que use todos los paquetes de brew python instalados.


En OSX El Capitan, lo que funcionó para mí fue forzar a pip a reinstalar la pcapy utilizando sudo: sudo pip install --user pcapy -I


Estoy ejecutando OSX 10.5.9 - gastado para siempre intentando que funcione scapy - después de instalar las bibliotecas dnet / pcap obtuve el "OSError: Dispositivo no configurado" también. Intenté reemplazar la línea 34 en unix.py con

"netstat -rn | grep -v vboxnet"

Todavía tiene el mismo error. Pero cuando cambio la línea 37 en lugar de la parte "else" del bloque if:

def read_routes(): if scapy.arch.SOLARIS: f=os.popen("netstat -rvn") # -f inet elif scapy.arch.FREEBSD: f=os.popen("netstat -rnW") # -W to handle long interface names else: # f=os.popen("netstat -rn") # -f inet f=os.popen("netstat -rn | grep -v vboxnet") # -f inet

¡Funciona de maravilla!


Todas las cuestiones mencionadas anteriormente parecen todas solucionadas. Estoy corriendo OS X Yosemite. Tengo un scapy de trabajo simplemente por los siguientes tres comandos.

brew install --with-python libdnet pip install pcapy pip install scapy


EDITAR : esta respuesta a continuación indica que todos los problemas mencionados fueron solucionados y proporciona un método de instalación mucho más sencillo. Sin embargo, sus comentarios sugieren que, aunque parece funcionar en OS X 10.10 Yosemite y OS X 10.11 El Capitan , puede fallar para algunas otras versiones.

No ha completado la instalación de libdnet y su envoltorio Python, como se indica en la guía de instalación de Scapy :

$ wget https://github.com/dugsong/libdnet/archive/libdnet-1.12.tar.gz $ tar xfz libdnet-1.12.tgz $ ./configure $ make $ sudo make install $ cd python $ python2.5 setup.py install

Si su sistema es de 64 bits, use estos comandos de compilación en su lugar:

$ CFLAGS=''-arch i386 -arch x86_64'' ./configure $ archargs=''-arch i386 -arch x86_64'' make

Además, verifique que haya instalado la versión correcta, es decir, 1.12 en lugar de 1.11.

Si eso también falla, intente instalar a través de macports y use su archivo dnet.so , como se describe here :

$ port selfupdate $ port upgrade outdated $ port install py27-libdnet $ port install libdnet $ cp /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dnet.so /Library/Python/2.7/site-packages

Ese enlace también recomienda cambiar algún código en /Library/Python/2.7/site-packages/scapy/arch/unix.py (corregir OSError: Device not configured ).

Cambiar línea 34 desde:

f=os.popen("netstat -rn") # -f inet

a:

f=os.popen("netstat -rn | grep -v vboxnet") # -f inet

como sigue:

def read_routes(): if scapy.arch.SOLARIS: # f=os.popen("netstat -rvn") # -f inet f=os.popen("netstat -rn | grep -v vboxnet") # -f inet

Si aún recibe el error OSError: Device not configured , intente realizar cambios similares en las otras ramas de la cláusula if (específicamente, en su else rama), como se describe en esta respuesta .